Commit 2f7e11ec75e85bfeeb0b52e0745d2b8d78228a8a
Committed by
Rodrigo Souto
1 parent
d4f50a7f
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 | 68 | expose :created_by, :as => :author, :using => Profile |
| 69 | 69 | expose :profile, :using => Profile |
| 70 | 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 | 73 | expose :children, :using => ArticleChild |
| 73 | 74 | expose :image, :using => Image |
| 74 | 75 | end | ... | ... |
lib/noosfero/api/v1/articles.rb
| ... | ... | @@ -33,7 +33,7 @@ module Noosfero |
| 33 | 33 | article = find_article(environment.articles, params[:id]) |
| 34 | 34 | articles = select_filtered_collection_of(article, 'children', params) |
| 35 | 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 | 37 | end |
| 38 | 38 | |
| 39 | 39 | get ':id/children/:child_id' do | ... | ... |