Commit b31129acce4dbc906f36fc1d865d4d9f834152cc
1 parent
a8e4e8b9
Exists in
staging
and in
32 other branches
api: filter unavailable comments
Showing
2 changed files
with
20 additions
and
1 deletions
Show diff stats
lib/noosfero/api/v1/comments.rb
... | ... | @@ -21,7 +21,8 @@ module Noosfero |
21 | 21 | article = find_article(environment.articles, params[:id]) |
22 | 22 | comments = select_filtered_collection_of(article, :comments, params) |
23 | 23 | comments = comments.without_reply if(params[:without_reply].present?) |
24 | - present comments, :with => Entities::Comment, :current_person => current_person | |
24 | + comments = plugins.filter(:unavailable_comments, comments) | |
25 | + present paginate(comments), :with => Entities::Comment, :current_person => current_person | |
25 | 26 | end |
26 | 27 | |
27 | 28 | get ":id/comments/:comment_id" do | ... | ... |
test/api/comments_test.rb
... | ... | @@ -100,4 +100,22 @@ class CommentsTest < ActiveSupport::TestCase |
100 | 100 | assert_equal 200, last_response.status |
101 | 101 | assert_equal [comment1.id], json["comments"].map { |c| c['id'] } |
102 | 102 | end |
103 | + | |
104 | + should 'call plugin hotspot to filter unavailable comments' do | |
105 | + class Plugin1 < Noosfero::Plugin | |
106 | + def unavailable_comments(scope) | |
107 | + scope.where(:user_agent => 'Jack') | |
108 | + end | |
109 | + end | |
110 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) | |
111 | + Environment.default.enable_plugin(Plugin1) | |
112 | + | |
113 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
114 | + c1 = fast_create(Comment, source_id: article.id, body: "comment 1") | |
115 | + c2 = fast_create(Comment, source_id: article.id, body: "comment 2", :user_agent => 'Jack') | |
116 | + | |
117 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
118 | + json = JSON.parse(last_response.body) | |
119 | + assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} | |
120 | + end | |
103 | 121 | end | ... | ... |