diff --git a/lib/noosfero/api/v1/comments.rb b/lib/noosfero/api/v1/comments.rb index c631190..a61569a 100644 --- a/lib/noosfero/api/v1/comments.rb +++ b/lib/noosfero/api/v1/comments.rb @@ -21,7 +21,8 @@ module Noosfero article = find_article(environment.articles, params[:id]) comments = select_filtered_collection_of(article, :comments, params) comments = comments.without_reply if(params[:without_reply].present?) - present comments, :with => Entities::Comment, :current_person => current_person + comments = plugins.filter(:unavailable_comments, comments) + present paginate(comments), :with => Entities::Comment, :current_person => current_person end get ":id/comments/:comment_id" do diff --git a/test/api/comments_test.rb b/test/api/comments_test.rb index b2aa960..6252b7f 100644 --- a/test/api/comments_test.rb +++ b/test/api/comments_test.rb @@ -100,4 +100,22 @@ class CommentsTest < ActiveSupport::TestCase assert_equal 200, last_response.status assert_equal [comment1.id], json["comments"].map { |c| c['id'] } end + + should 'call plugin hotspot to filter unavailable comments' do + class Plugin1 < Noosfero::Plugin + def unavailable_comments(scope) + scope.where(:user_agent => 'Jack') + end + end + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) + Environment.default.enable_plugin(Plugin1) + + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + c1 = fast_create(Comment, source_id: article.id, body: "comment 1") + c2 = fast_create(Comment, source_id: article.id, body: "comment 2", :user_agent => 'Jack') + + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} + end end -- libgit2 0.21.2