Commit f19bda317c30156b406a33d6b87188e474f5ca7d
Committed by
Rodrigo Souto
1 parent
a7b2bd76
Exists in
master
and in
29 other branches
api: limit returned fields in articles children
Showing
2 changed files
with
3 additions
and
2 deletions
Show diff stats
lib/noosfero/api/entities.rb
@@ -68,7 +68,8 @@ module Noosfero | @@ -68,7 +68,8 @@ module Noosfero | ||
68 | expose :created_by, :as => :author, :using => Profile | 68 | expose :created_by, :as => :author, :using => Profile |
69 | expose :profile, :using => Profile | 69 | expose :profile, :using => Profile |
70 | expose :categories, :using => Category | 70 | expose :categories, :using => Category |
71 | - expose :parent, :using => Article | 71 | + # FIXME: create a method that overrides expose and include conditions for return attributes |
72 | + expose :parent, :using => Article, :if => lambda { |article, options| options[:fields].blank? || options[:fields].include?(:parent) } | ||
72 | expose :children, :using => ArticleChild | 73 | expose :children, :using => ArticleChild |
73 | expose :image, :using => Image | 74 | expose :image, :using => Image |
74 | end | 75 | end |
lib/noosfero/api/v1/articles.rb
@@ -33,7 +33,7 @@ module Noosfero | @@ -33,7 +33,7 @@ module Noosfero | ||
33 | article = find_article(environment.articles, params[:id]) | 33 | article = find_article(environment.articles, params[:id]) |
34 | articles = select_filtered_collection_of(article, 'children', params) | 34 | articles = select_filtered_collection_of(article, 'children', params) |
35 | articles = articles.display_filter(current_person, nil) | 35 | articles = articles.display_filter(current_person, nil) |
36 | - present articles, :with => Entities::Article | 36 | + present articles, :with => Entities::Article, :fields => [:id, :name, :abstract, :author] |
37 | end | 37 | end |
38 | 38 | ||
39 | get ':id/children/:child_id' do | 39 | get ':id/children/:child_id' do |