Commit d6081ef03622aea2c119ba85d5a4317bd0c6ba5e

Authored by Caio Almeida
1 parent 01edd235

Adding filter to article api children

app/models/environment.rb
@@ -474,7 +474,8 @@ class Environment < ActiveRecord::Base @@ -474,7 +474,8 @@ class Environment < ActiveRecord::Base
474 end 474 end
475 475
476 def custom_person_fields 476 def custom_person_fields
477 - self.settings[:custom_person_fields].nil? ? {} : self.settings[:custom_person_fields] 477 + self.settings[:custom_person_fields] = {} if self.settings[:custom_person_fields].nil?
  478 + self.settings[:custom_person_fields]
478 end 479 end
479 480
480 def custom_person_fields=(values) 481 def custom_person_fields=(values)
lib/noosfero/api/entities.rb
@@ -30,10 +30,30 @@ module Noosfero @@ -30,10 +30,30 @@ module Noosfero
30 end 30 end
31 end 31 end
32 32
  33 + class CategoryBase < Entity
  34 + root 'categories', 'category'
  35 + expose :name, :id, :slug
  36 + end
  37 +
  38 + class Category < CategoryBase
  39 + root 'categories', 'category'
  40 + expose :full_name do |category, options|
  41 + category.full_name
  42 + end
  43 + expose :parent, :using => CategoryBase, if: { parent: true }
  44 + expose :children, :using => CategoryBase, if: { children: true }
  45 + expose :image, :using => Image
  46 + end
  47 +
  48 + class Region < Category
  49 + root 'regions', 'region'
  50 + end
  51 +
33 class Profile < Entity 52 class Profile < Entity
34 expose :identifier, :name, :id 53 expose :identifier, :name, :id
35 expose :created_at, :format_with => :timestamp 54 expose :created_at, :format_with => :timestamp
36 expose :image, :using => Image 55 expose :image, :using => Image
  56 + expose :region, :using => Region
37 end 57 end
38 58
39 class UserBasic < Entity 59 class UserBasic < Entity
@@ -55,21 +75,6 @@ module Noosfero @@ -55,21 +75,6 @@ module Noosfero
55 expose :description 75 expose :description
56 end 76 end
57 77
58 - class CategoryBase < Entity  
59 - root 'categories', 'category'  
60 - expose :name, :id, :slug  
61 - end  
62 -  
63 - class Category < CategoryBase  
64 - root 'categories', 'category'  
65 - expose :full_name do |category, options|  
66 - category.full_name  
67 - end  
68 - expose :parent, :using => CategoryBase, if: { parent: true }  
69 - expose :children, :using => CategoryBase, if: { children: true }  
70 - expose :image, :using => Image  
71 - end  
72 -  
73 class ArticleBase < Entity 78 class ArticleBase < Entity
74 root 'articles', 'article' 79 root 'articles', 'article'
75 expose :id 80 expose :id
lib/noosfero/api/helpers.rb
@@ -103,8 +103,8 @@ require &#39;grape&#39; @@ -103,8 +103,8 @@ require &#39;grape&#39;
103 present articles, :with => Entities::Article, :fields => params[:fields] 103 present articles, :with => Entities::Article, :fields => params[:fields]
104 end 104 end
105 105
106 - def find_articles(asset)  
107 - articles = select_filtered_collection_of(asset, 'articles', params) 106 + def find_articles(asset, method = 'articles')
  107 + articles = select_filtered_collection_of(asset, method, params)
108 if current_person.present? 108 if current_person.present?
109 articles = articles.display_filter(current_person, nil) 109 articles = articles.display_filter(current_person, nil)
110 else 110 else
lib/noosfero/api/v1/articles.rb
@@ -95,9 +95,8 @@ module Noosfero @@ -95,9 +95,8 @@ module Noosfero
95 95
96 #TODO make tests for this situation 96 #TODO make tests for this situation
97 votes_order = params.delete(:order) if params[:order]=='votes_score' 97 votes_order = params.delete(:order) if params[:order]=='votes_score'
98 - articles = select_filtered_collection_of(article, 'children', params)  
99 - articles = articles.display_filter(current_person, article.profile)  
100 98
  99 + articles = find_articles(article, 'children')
101 100
102 #TODO make tests for this situation 101 #TODO make tests for this situation
103 if votes_order 102 if votes_order
plugins/juventude
1 -Subproject commit b8cd73843df709c6e039e042d93b0bba843f58ec 1 +Subproject commit 08b594d907791da12c9097f355d8ee6a715bd14a