Commit d6081ef03622aea2c119ba85d5a4317bd0c6ba5e
1 parent
01edd235
Exists in
staging
and in
4 other branches
Adding filter to article api children
Showing
5 changed files
with
26 additions
and
21 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -474,7 +474,8 @@ class Environment < ActiveRecord::Base |
474 | 474 | end |
475 | 475 | |
476 | 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 | 479 | end |
479 | 480 | |
480 | 481 | def custom_person_fields=(values) | ... | ... |
lib/noosfero/api/entities.rb
... | ... | @@ -30,10 +30,30 @@ module Noosfero |
30 | 30 | end |
31 | 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 | 52 | class Profile < Entity |
34 | 53 | expose :identifier, :name, :id |
35 | 54 | expose :created_at, :format_with => :timestamp |
36 | 55 | expose :image, :using => Image |
56 | + expose :region, :using => Region | |
37 | 57 | end |
38 | 58 | |
39 | 59 | class UserBasic < Entity |
... | ... | @@ -55,21 +75,6 @@ module Noosfero |
55 | 75 | expose :description |
56 | 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 | 78 | class ArticleBase < Entity |
74 | 79 | root 'articles', 'article' |
75 | 80 | expose :id | ... | ... |
lib/noosfero/api/helpers.rb
... | ... | @@ -103,8 +103,8 @@ require 'grape' |
103 | 103 | present articles, :with => Entities::Article, :fields => params[:fields] |
104 | 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 | 108 | if current_person.present? |
109 | 109 | articles = articles.display_filter(current_person, nil) |
110 | 110 | else | ... | ... |
lib/noosfero/api/v1/articles.rb
... | ... | @@ -95,9 +95,8 @@ module Noosfero |
95 | 95 | |
96 | 96 | #TODO make tests for this situation |
97 | 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 | 101 | #TODO make tests for this situation |
103 | 102 | if votes_order | ... | ... |
plugins/juventude