Commit d8a07bd4bd314566ff9b7b79ca437f3f8ad38dc8

Authored by Victor Costa
1 parent 0ee6f0f6

Fix display filter for article children

lib/noosfero/api/helpers.rb
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 56
57 def find_article(articles, id) 57 def find_article(articles, id)
58 article = articles.find(id) 58 article = articles.find(id)
59 - article.display_to?(current_user.person) ? article : forbidden! 59 + article.display_to?(current_person) ? article : forbidden!
60 end 60 end
61 61
62 def post_article(asset, params) 62 def post_article(asset, params)
lib/noosfero/api/v1/articles.rb
@@ -96,7 +96,7 @@ module Noosfero @@ -96,7 +96,7 @@ module Noosfero
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) 98 articles = select_filtered_collection_of(article, 'children', params)
99 - articles = articles.display_filter(current_person, nil) 99 + articles = articles.display_filter(current_person, article.profile)
100 100
101 101
102 #TODO make tests for this situation 102 #TODO make tests for this situation
test/unit/api/articles_test.rb
@@ -48,6 +48,15 @@ class ArticlesTest < ActiveSupport::TestCase @@ -48,6 +48,15 @@ class ArticlesTest < ActiveSupport::TestCase
48 assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] } 48 assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] }
49 end 49 end
50 50
  51 + should 'list public article children for not logged in access' do
  52 + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  53 + child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")
  54 + child2 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")
  55 + get "/api/v1/articles/#{article.id}/children"
  56 + json = JSON.parse(last_response.body)
  57 + assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] }
  58 + end
  59 +
51 should 'not list children of forbidden article' do 60 should 'not list children of forbidden article' do
52 person = fast_create(Person) 61 person = fast_create(Person)
53 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 62 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)