Commit b4d35439e69c6974c794b547c76d85cd94bd4b5f
1 parent
b31129ac
Exists in
web_steps_improvements
and in
6 other branches
api: not return comments marked as spam
Showing
4 changed files
with
24 additions
and
0 deletions
Show diff stats
lib/noosfero/api/v1/comments.rb
... | ... | @@ -20,6 +20,7 @@ module Noosfero |
20 | 20 | get ":id/comments" do |
21 | 21 | article = find_article(environment.articles, params[:id]) |
22 | 22 | comments = select_filtered_collection_of(article, :comments, params) |
23 | + comments = comments.without_spam | |
23 | 24 | comments = comments.without_reply if(params[:without_reply].present?) |
24 | 25 | comments = plugins.filter(:unavailable_comments, comments) |
25 | 26 | present paginate(comments), :with => Entities::Comment, :current_person => current_person | ... | ... |
plugins/comment_paragraph/lib/comment_paragraph_plugin/api.rb
... | ... | @@ -6,6 +6,7 @@ class CommentParagraphPlugin::API < Grape::API |
6 | 6 | get ':id/comment_paragraph_plugin/comments' do |
7 | 7 | article = find_article(environment.articles, params[:id]) |
8 | 8 | comments = select_filtered_collection_of(article, :comments, params) |
9 | + comments = comments.without_spam | |
9 | 10 | comments = comments.in_paragraph(params[:paragraph_uuid]) |
10 | 11 | comments = comments.without_reply if(params[:without_reply].present?) |
11 | 12 | present paginate(comments), :with => Noosfero::API::Entities::Comment, :current_person => current_person | ... | ... |
plugins/comment_paragraph/test/unit/api_test.rb
... | ... | @@ -68,4 +68,16 @@ class APITest < ActiveSupport::TestCase |
68 | 68 | json = JSON.parse(last_response.body) |
69 | 69 | assert_equal({"1"=>1, ""=>1, "2"=>2}, json) |
70 | 70 | end |
71 | + | |
72 | + should 'filter comments marked as spam' do | |
73 | + article = fast_create(TextArticle, :profile_id => person.id, :name => "Some thing", :published => false) | |
74 | + comment1 = fast_create(Comment, :paragraph_uuid => '1', :source_id => article.id) | |
75 | + comment2 = fast_create(Comment, :paragraph_uuid => nil, :source_id => article.id, spam: true) | |
76 | + comment3 = fast_create(Comment, :paragraph_uuid => '2', :source_id => article.id, spam: true) | |
77 | + params[:paragraph_uuid] = '1' | |
78 | + get "/api/v1/articles/#{article.id}/comment_paragraph_plugin/comments?#{params.to_query}" | |
79 | + | |
80 | + json = JSON.parse(last_response.body) | |
81 | + assert_equivalent [comment1.id], json['comments'].map {|c| c['id']} | |
82 | + end | |
71 | 83 | end | ... | ... |
test/api/comments_test.rb
... | ... | @@ -118,4 +118,14 @@ class CommentsTest < ActiveSupport::TestCase |
118 | 118 | json = JSON.parse(last_response.body) |
119 | 119 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} |
120 | 120 | end |
121 | + | |
122 | + should 'do not return comments marked as spam' do | |
123 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
124 | + c1 = fast_create(Comment, source_id: article.id, body: "comment 1", spam: true) | |
125 | + c2 = fast_create(Comment, source_id: article.id, body: "comment 2") | |
126 | + | |
127 | + get "/api/v1/articles/#{article.id}/comments?#{params.to_query}" | |
128 | + json = JSON.parse(last_response.body) | |
129 | + assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} | |
130 | + end | |
121 | 131 | end | ... | ... |