Skip to content

Commit

Permalink
Spam comment moderation (#2957)
Browse files Browse the repository at this point in the history
* change to status 1

* mark spam button for moderator and admin

* ban user if comment marked as spam

* test fix

* danger file using message
  • Loading branch information
grvsachdeva authored and jywarren committed Jul 10, 2018
1 parent 4e6689e commit d866329
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ begin

rescue => ex
fail "There was an error with Danger bot's Junit parsing: #{ex.message}"
puts ex.inspect # view the entire error output in the log
message ex.inspect # view the entire error output in the log
end
4 changes: 3 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def mark_comment_spam
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
if @comment.status == 1
@comment.spam
flash[:notice] = "Comment has been marked as spam."
user = @comment.author
user.ban
flash[:notice] = "Comment has been marked as spam and comment author has been banned."
else
flash[:notice] = "Comment already marked as spam."
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def profile
.limit(20)
@wikis = wikis.collect(&:parent).uniq

@comment_count = Comment.where(status: 0, uid: @user.uid).count
@comment_count = Comment.where(status: 1, uid: @user.uid).count

# User's social links
@github = @profile_user.social_link("github")
Expand Down Expand Up @@ -259,7 +259,7 @@ def reset
def comments
@comments = Comment.limit(20)
.order("timestamp DESC")
.where(status: 0, uid: params[:id])
.where(status: 1, uid: params[:id])
.paginate(page: params[:page])
render partial: 'comments/comments'
end
Expand Down
13 changes: 10 additions & 3 deletions app/views/notes/_comment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@
<% if comment.comment_via == 1 %>
<a href="#" onclick="return false;" class="btn btn-default btn-sm"><i class="fa fa-envelope"></i></a>
<% end %>
<a rel="tooltip" title="Flag as spam" class="btn btn-sm btn-default btn-flag-spam-<%= comment.id %>" href="mailto:moderators@publiclab.org?subject=Reporting+spam+on+Public+Lab&body=Hi,+I+found+this+comment+that+looks+like+spam+or+needs+to+be+moderated:+https://publiclab.org/<%= comment.parent.path %>#c<%= comment.cid %>+by+https://publiclab.org/profile/<% if comment.author %><%= comment.author.name %><% end %>+Thanks!">
<i class="fa fa-flag"></i>
</a>
<% if current_user &. can_moderate? %>
<a rel="tooltip" title="Mark as spam" class="btn btn-sm btn-default btn-flag-spam-<%= comment.id %>" data-confirm="Are you sure? The user will no longer be able to log in or publish, and their content will be hidden except comments." href="/admin/mark_comment_spam/<%= comment.id %>">
<i class="fa fa-ban"></i>
</a>
<% else %>
<a rel="tooltip" title="Flag as spam" class="btn btn-sm btn-default btn-flag-spam-<%= comment.id %>" href="mailto:moderators@publiclab.org?subject=Reporting+spam+on+Public+Lab&body=Hi,+I+found+this+comment+that+looks+like+spam+or+needs+to+be+moderated:+https://publiclab.org/<%= comment.parent.path %>#c<%= comment.cid %>+by+https://publiclab.org/profile/<% if comment.author %><%= comment.author.name %><% end %>+Thanks!">
<i class="fa fa-flag"></i>
</a>
<% end %>

<% if current_user && (current_user.role == "admin" || current_user.role == "moderator" || comment.uid == current_user.uid || comment.parent.uid == current_user.uid) %>
<a class="btn btn-default btn-sm" id="c<%= comment.cid %>delete-btn">
<i class='icon fa fa-trash'></i>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notes/_comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="row">
<div id="comments" class="col-md-10 comments">

<h3><span id="comment-count"><%= @node.comments.length %></span> <%= t('notes._comments.comments') %></h3>
<h3><span id="comment-count"><%= @node.comments.where(status: 1).length %></span> <%= t('notes._comments.comments') %></h3>

<div style="margin-bottom: 50px;" id="comments-container">
<% @node.comments.order('timestamp ASC').each do |comment| %>
<% @node.comments.where(status: 1).order('timestamp ASC').each do |comment| %>
<% if comment.cid == @node.comments.first.cid %><a id="last" name="last"></a><% end %>

<%= render :partial => "notes/comment", :locals => {:comment => comment} %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
get 'admin/moderate/:id' => 'admin#moderate'
get 'admin/unmoderate/:id' => 'admin#unmoderate'
get 'admin/publish_comment/:id' => 'admin#publish_comment'
post 'admin/mark_comment_spam/:id' => 'admin#mark_comment_spam'
get 'admin/mark_comment_spam/:id' => 'admin#mark_comment_spam'

get 'post' => 'editor#post'
post 'post' => 'editor#post'
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ spam_comment:
nid: 1
status: 0
comment: This thing is spam.
timestamp: <%= Time.now.to_i + 1 %>
timestamp: <%= Time.now.to_i + 14 %>
thread: /01
6 changes: 4 additions & 2 deletions test/functional/admin_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def teardown

comment = assigns(:comment)
assert_equal 0, comment.status
assert_equal "Comment has been marked as spam.", flash[:notice]

assert_equal "Comment has been marked as spam and comment author has been banned.", flash[:notice]
assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s
end

Expand All @@ -434,7 +435,8 @@ def teardown

comment = assigns(:comment)
assert_equal 0, comment.status
assert_equal "Comment has been marked as spam.", flash[:notice]

assert_equal "Comment has been marked as spam and comment author has been banned.", flash[:notice]
assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s
end

Expand Down
2 changes: 1 addition & 1 deletion test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def teardown
id: node.title.parameterize
}
selector = css_select '.fa-fire'
assert_equal selector.size, 4
assert_equal selector.size, 3
end

test 'should redirect to questions show page after creating a new question' do
Expand Down

0 comments on commit d866329

Please sign in to comment.