Commit 2382a9652197ac247ba2983fe4243cf23e854ac2
1 parent
5521d9b4
Exists in
master
and in
29 other branches
UI to mark comments as SPAM
Plus a small enhancements on the existing UI for comments: turned the "delete" button into a text-only label in the bottom, instead of an annoying icon that shows up when you pass the mouse over the comment balloon. ActionItem2306
Showing
8 changed files
with
65 additions
and
26 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -75,8 +75,14 @@ class ContentViewerController < ApplicationController | @@ -75,8 +75,14 @@ class ContentViewerController < ApplicationController | ||
75 | @comment = Comment.new | 75 | @comment = Comment.new |
76 | end | 76 | end |
77 | 77 | ||
78 | - if request.post? && params[:remove_comment] | ||
79 | - remove_comment | 78 | + if request.post? |
79 | + if params[:remove_comment] | ||
80 | + remove_comment | ||
81 | + return | ||
82 | + elsif params[:mark_comment_as_spam] | ||
83 | + mark_comment_as_spam | ||
84 | + return | ||
85 | + end | ||
80 | end | 86 | end |
81 | 87 | ||
82 | if @page.has_posts? | 88 | if @page.has_posts? |
@@ -107,8 +113,9 @@ class ContentViewerController < ApplicationController | @@ -107,8 +113,9 @@ class ContentViewerController < ApplicationController | ||
107 | end | 113 | end |
108 | end | 114 | end |
109 | 115 | ||
110 | - @comments = @page.comments(true).as_thread | ||
111 | - @comments_count = @page.comments.count | 116 | + comments = @page.comments.without_spam |
117 | + @comments = comments.as_thread | ||
118 | + @comments_count = comments.count | ||
112 | if params[:slideshow] | 119 | if params[:slideshow] |
113 | render :action => 'slideshow', :layout => 'slideshow' | 120 | render :action => 'slideshow', :layout => 'slideshow' |
114 | end | 121 | end |
@@ -151,6 +158,15 @@ class ContentViewerController < ApplicationController | @@ -151,6 +158,15 @@ class ContentViewerController < ApplicationController | ||
151 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] | 158 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] |
152 | end | 159 | end |
153 | 160 | ||
161 | + def mark_comment_as_spam | ||
162 | + @comment = @page.comments.find(params[:mark_comment_as_spam]) | ||
163 | + if logged_in? && (user == @page.profile || user.has_permission?(:moderate_comments, @page.profile)) | ||
164 | + @comment.spam! | ||
165 | + session[:notice] = _('Comment succesfully marked as SPAM') | ||
166 | + end | ||
167 | + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] | ||
168 | + end | ||
169 | + | ||
154 | def per_page | 170 | def per_page |
155 | 12 | 171 | 12 |
156 | end | 172 | end |
app/helpers/content_viewer_helper.rb
@@ -4,7 +4,7 @@ module ContentViewerHelper | @@ -4,7 +4,7 @@ module ContentViewerHelper | ||
4 | include ForumHelper | 4 | include ForumHelper |
5 | 5 | ||
6 | def number_of_comments(article) | 6 | def number_of_comments(article) |
7 | - n = article.comments.size | 7 | + n = article.comments.without_spam.count |
8 | if n == 0 | 8 | if n == 0 |
9 | _('No comments yet') | 9 | _('No comments yet') |
10 | else | 10 | else |
app/models/comment.rb
app/views/content_viewer/_comment.rhtml
@@ -29,17 +29,12 @@ | @@ -29,17 +29,12 @@ | ||
29 | <% end %> | 29 | <% end %> |
30 | 30 | ||
31 | <% comment_balloon do %> | 31 | <% comment_balloon do %> |
32 | - <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> | ||
33 | - <% button_bar(:style => 'float: right; margin-top: 0px;') do %> | ||
34 | - <%= 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?')) %> | ||
35 | - <% end %> | ||
36 | - <% end %> | ||
37 | 32 | ||
38 | <div class="comment-details"> | 33 | <div class="comment-details"> |
39 | <div class="comment-created-at"> | 34 | <div class="comment-created-at"> |
40 | <%= show_time(comment.created_at) %> | 35 | <%= show_time(comment.created_at) %> |
41 | </div> | 36 | </div> |
42 | - <h4><%= comment.title %></h4> | 37 | + <h4><%= comment.title.blank? && ' ' || comment.title %></h4> |
43 | <div class="comment-text"> | 38 | <div class="comment-text"> |
44 | <p/> | 39 | <p/> |
45 | <%= txt2html comment.body %> | 40 | <%= txt2html comment.body %> |
@@ -57,6 +52,17 @@ | @@ -57,6 +52,17 @@ | ||
57 | </script> | 52 | </script> |
58 | <% end %> | 53 | <% end %> |
59 | <%= report_abuse(comment.author, :comment_link, comment) if comment.author %> | 54 | <%= report_abuse(comment.author, :comment_link, comment) if comment.author %> |
55 | + | ||
56 | + <% if (logged_in? && (user == @page.profile || user.has_permission?(:moderate_comments, @page.profile))) %> | ||
57 | + <%= 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') %> | ||
58 | + | ||
59 | + <% end %> | ||
60 | + | ||
61 | + <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> | ||
62 | + <%= 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') %> | ||
63 | + | ||
64 | + <% end %> | ||
65 | + | ||
60 | <%= link_to_function _('Reply'), | 66 | <%= link_to_function _('Reply'), |
61 | "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id, | 67 | "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id, |
62 | :class => 'comment-footer comment-footer-link comment-footer-hide', | 68 | :class => 'comment-footer comment-footer-link comment-footer-hide', |
app/views/content_viewer/view_page.rhtml
@@ -99,12 +99,6 @@ | @@ -99,12 +99,6 @@ | ||
99 | 99 | ||
100 | <% if @page.accept_comments? %> | 100 | <% if @page.accept_comments? %> |
101 | <div id="page-comment-form"><%= render :partial => 'comment_form' %></div> | 101 | <div id="page-comment-form"><%= render :partial => 'comment_form' %></div> |
102 | - <script type="text/javascript"> | ||
103 | - jQuery( function() { | ||
104 | - jQuery('.article-comment').live('mouseover', function() { jQuery(this).find('.icon-delete:first').show(); }); | ||
105 | - jQuery('.article-comment').live('mouseout', function() { jQuery(this).find('.icon-delete').hide(); }); | ||
106 | - }); | ||
107 | - </script> | ||
108 | <% end %> | 102 | <% end %> |
109 | </div><!-- end class="comments" --> | 103 | </div><!-- end class="comments" --> |
110 | 104 |
public/stylesheets/application.css
@@ -1069,15 +1069,6 @@ a.comment-picture { | @@ -1069,15 +1069,6 @@ a.comment-picture { | ||
1069 | top: 9px; | 1069 | top: 9px; |
1070 | right: 8px; | 1070 | right: 8px; |
1071 | } | 1071 | } |
1072 | -#content .comment-balloon a.button.icon-delete { | ||
1073 | - border: 0; | ||
1074 | - padding-top: 0; | ||
1075 | - padding-bottom: 0; | ||
1076 | - background-color: transparent; | ||
1077 | -} | ||
1078 | -#content .comments .comment-balloon a.button.icon-delete { | ||
1079 | - display: none; | ||
1080 | -} | ||
1081 | .msie7 .article-comments-list .comment-balloon { | 1072 | .msie7 .article-comments-list .comment-balloon { |
1082 | margin-top: -15px; | 1073 | margin-top: -15px; |
1083 | } | 1074 | } |
test/functional/content_viewer_controller_test.rb
@@ -1407,4 +1407,24 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -1407,4 +1407,24 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
1407 | assert_not_includes Article.find(article.id).followers, follower_email | 1407 | assert_not_includes Article.find(article.id).followers, follower_email |
1408 | end | 1408 | end |
1409 | 1409 | ||
1410 | + should 'not display comments marked as spam' do | ||
1411 | + article = fast_create(Article, :profile_id => profile.id) | ||
1412 | + ham = fast_create(Comment, :source_id => article.id) | ||
1413 | + spam = fast_create(Comment, :source_id => article.id, :spam => true) | ||
1414 | + | ||
1415 | + get 'view_page', :profile => profile.identifier, :page => article.path.split('/') | ||
1416 | + assert_equal 1, assigns(:comments_count) | ||
1417 | + end | ||
1418 | + | ||
1419 | + should 'be able to mark comments as spam' do | ||
1420 | + login_as profile.identifier | ||
1421 | + article = fast_create(Article, :profile_id => profile.id) | ||
1422 | + spam = fast_create(Comment, :name => 'foo', :email => 'foo@example.com', :source_id => article.id) | ||
1423 | + | ||
1424 | + post 'view_page', :profile => profile.identifier, :page => article.path.split('/'), :mark_comment_as_spam => spam.id | ||
1425 | + | ||
1426 | + spam.reload | ||
1427 | + assert spam.spam? | ||
1428 | + end | ||
1429 | + | ||
1410 | end | 1430 | end |
test/unit/comment_test.rb
@@ -445,4 +445,11 @@ class CommentTest < ActiveSupport::TestCase | @@ -445,4 +445,11 @@ class CommentTest < ActiveSupport::TestCase | ||
445 | assert_equivalent [c1,c2], Comment.without_spam | 445 | assert_equivalent [c1,c2], Comment.without_spam |
446 | end | 446 | end |
447 | 447 | ||
448 | + should 'be able to mark as spam atomically' do | ||
449 | + c1 = fast_create(Comment, :name => 'foo', :email => 'foo@example.com') | ||
450 | + c1.spam! | ||
451 | + c1.reload | ||
452 | + assert c1.spam? | ||
453 | + end | ||
454 | + | ||
448 | end | 455 | end |