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,6 +20,7 @@ module Noosfero | ||
20 | get ":id/comments" do | 20 | get ":id/comments" do |
21 | article = find_article(environment.articles, params[:id]) | 21 | article = find_article(environment.articles, params[:id]) |
22 | comments = select_filtered_collection_of(article, :comments, params) | 22 | comments = select_filtered_collection_of(article, :comments, params) |
23 | + comments = comments.without_spam | ||
23 | comments = comments.without_reply if(params[:without_reply].present?) | 24 | comments = comments.without_reply if(params[:without_reply].present?) |
24 | comments = plugins.filter(:unavailable_comments, comments) | 25 | comments = plugins.filter(:unavailable_comments, comments) |
25 | present paginate(comments), :with => Entities::Comment, :current_person => current_person | 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 +6,7 @@ class CommentParagraphPlugin::API < Grape::API | ||
6 | get ':id/comment_paragraph_plugin/comments' do | 6 | get ':id/comment_paragraph_plugin/comments' do |
7 | article = find_article(environment.articles, params[:id]) | 7 | article = find_article(environment.articles, params[:id]) |
8 | comments = select_filtered_collection_of(article, :comments, params) | 8 | comments = select_filtered_collection_of(article, :comments, params) |
9 | + comments = comments.without_spam | ||
9 | comments = comments.in_paragraph(params[:paragraph_uuid]) | 10 | comments = comments.in_paragraph(params[:paragraph_uuid]) |
10 | comments = comments.without_reply if(params[:without_reply].present?) | 11 | comments = comments.without_reply if(params[:without_reply].present?) |
11 | present paginate(comments), :with => Noosfero::API::Entities::Comment, :current_person => current_person | 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,4 +68,16 @@ class APITest < ActiveSupport::TestCase | ||
68 | json = JSON.parse(last_response.body) | 68 | json = JSON.parse(last_response.body) |
69 | assert_equal({"1"=>1, ""=>1, "2"=>2}, json) | 69 | assert_equal({"1"=>1, ""=>1, "2"=>2}, json) |
70 | end | 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 | end | 83 | end |
test/api/comments_test.rb
@@ -118,4 +118,14 @@ class CommentsTest < ActiveSupport::TestCase | @@ -118,4 +118,14 @@ class CommentsTest < ActiveSupport::TestCase | ||
118 | json = JSON.parse(last_response.body) | 118 | json = JSON.parse(last_response.body) |
119 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} | 119 | assert_equal ["comment 2"], json["comments"].map {|c| c["body"]} |
120 | end | 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 | end | 131 | end |