From 2382a9652197ac247ba2983fe4243cf23e854ac2 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 20 Aug 2012 15:00:28 -0300 Subject: [PATCH] UI to mark comments as SPAM --- app/controllers/public/content_viewer_controller.rb | 24 ++++++++++++++++++++---- app/helpers/content_viewer_helper.rb | 2 +- app/models/comment.rb | 5 +++++ app/views/content_viewer/_comment.rhtml | 18 ++++++++++++------ app/views/content_viewer/view_page.rhtml | 6 ------ public/stylesheets/application.css | 9 --------- test/functional/content_viewer_controller_test.rb | 20 ++++++++++++++++++++ test/unit/comment_test.rb | 7 +++++++ 8 files changed, 65 insertions(+), 26 deletions(-) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 84ccf9b..ce5f222 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -75,8 +75,14 @@ class ContentViewerController < ApplicationController @comment = Comment.new end - if request.post? && params[:remove_comment] - remove_comment + if request.post? + if params[:remove_comment] + remove_comment + return + elsif params[:mark_comment_as_spam] + mark_comment_as_spam + return + end end if @page.has_posts? @@ -107,8 +113,9 @@ class ContentViewerController < ApplicationController end end - @comments = @page.comments(true).as_thread - @comments_count = @page.comments.count + comments = @page.comments.without_spam + @comments = comments.as_thread + @comments_count = comments.count if params[:slideshow] render :action => 'slideshow', :layout => 'slideshow' end @@ -151,6 +158,15 @@ class ContentViewerController < ApplicationController redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] end + def mark_comment_as_spam + @comment = @page.comments.find(params[:mark_comment_as_spam]) + if logged_in? && (user == @page.profile || user.has_permission?(:moderate_comments, @page.profile)) + @comment.spam! + session[:notice] = _('Comment succesfully marked as SPAM') + end + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] + end + def per_page 12 end diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 524aa53..38b81b3 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -4,7 +4,7 @@ module ContentViewerHelper include ForumHelper def number_of_comments(article) - n = article.comments.size + n = article.comments.without_spam.count if n == 0 _('No comments yet') else diff --git a/app/models/comment.rb b/app/models/comment.rb index db383cb..de6991b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -198,4 +198,9 @@ class Comment < ActiveRecord::Base !spam.nil? && !spam end + def spam! + self.spam = true + self.save! + end + end diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml index 1a9d895..3f1009f 100644 --- a/app/views/content_viewer/_comment.rhtml +++ b/app/views/content_viewer/_comment.rhtml @@ -29,17 +29,12 @@ <% end %> <% comment_balloon do %> - <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> - <% button_bar(:style => 'float: right; margin-top: 0px;') do %> - <%= icon_button(:delete, _('Remove this comment and all its replies'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> - <% end %> - <% end %>
<%= show_time(comment.created_at) %>
-

<%= comment.title %>

+

<%= comment.title.blank? && ' ' || comment.title %>

<%= txt2html comment.body %> @@ -57,6 +52,17 @@ <% end %> <%= report_abuse(comment.author, :comment_link, comment) if comment.author %> + + <% if (logged_in? && (user == @page.profile || user.has_permission?(:moderate_comments, @page.profile))) %> + <%= link_to(_('Mark as SPAM'), { :mark_comment_as_spam => comment.id }, :method => :post, :confirm => _('Are you sure you want to mark this comment as SPAM?'), :class => 'comment-footer comment-footer-link comment-footer-hide') %> +   + <% end %> + + <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> + <%= link_to(_('Remove'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?'), :class => 'comment-footer comment-footer-link comment-footer-hide') %> +   + <% end %> + <%= link_to_function _('Reply'), "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id, :class => 'comment-footer comment-footer-link comment-footer-hide', diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 3295dcb..40faed9 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -99,12 +99,6 @@ <% if @page.accept_comments? %>

<%= render :partial => 'comment_form' %>
- <% end %>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index b5cdd86..10488f0 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1069,15 +1069,6 @@ a.comment-picture { top: 9px; right: 8px; } -#content .comment-balloon a.button.icon-delete { - border: 0; - padding-top: 0; - padding-bottom: 0; - background-color: transparent; -} -#content .comments .comment-balloon a.button.icon-delete { - display: none; -} .msie7 .article-comments-list .comment-balloon { margin-top: -15px; } diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 9da6370..6111095 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -1407,4 +1407,24 @@ class ContentViewerControllerTest < ActionController::TestCase assert_not_includes Article.find(article.id).followers, follower_email end + should 'not display comments marked as spam' do + article = fast_create(Article, :profile_id => profile.id) + ham = fast_create(Comment, :source_id => article.id) + spam = fast_create(Comment, :source_id => article.id, :spam => true) + + get 'view_page', :profile => profile.identifier, :page => article.path.split('/') + assert_equal 1, assigns(:comments_count) + end + + should 'be able to mark comments as spam' do + login_as profile.identifier + article = fast_create(Article, :profile_id => profile.id) + spam = fast_create(Comment, :name => 'foo', :email => 'foo@example.com', :source_id => article.id) + + post 'view_page', :profile => profile.identifier, :page => article.path.split('/'), :mark_comment_as_spam => spam.id + + spam.reload + assert spam.spam? + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 274d7cd..77036e5 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -445,4 +445,11 @@ class CommentTest < ActiveSupport::TestCase assert_equivalent [c1,c2], Comment.without_spam end + should 'be able to mark as spam atomically' do + c1 = fast_create(Comment, :name => 'foo', :email => 'foo@example.com') + c1.spam! + c1.reload + assert c1.spam? + end + end -- libgit2 0.21.2