moderators have to provide a reason for deleting others' comments

This commit is contained in:
joshua stein 2016-02-10 08:57:38 -06:00
parent 3afe1538f8
commit 28bbc9c8f7
4 changed files with 24 additions and 3 deletions

View file

@ -368,6 +368,18 @@ $(document).ready(function() {
}
});
$(document).on("click", "a.comment_moderator", function() {
var reason = prompt("Moderation reason:");
if (reason == null || reason == "")
return false;
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/delete",
{ reason: reason }, function(d) {
$(li).replaceWith(d);
});
});
$(document).on("click", "a.comment_undeletor", function() {
if (confirm("Are you sure you want to undelete this comment?")) {
var li = $(this).closest(".comment");

View file

@ -111,7 +111,7 @@ class CommentsController < ApplicationController
return render :text => "can't find comment", :status => 400
end
comment.delete_for_user(@user)
comment.delete_for_user(@user, params[:reason])
render :partial => "comment", :layout => false,
:content_type => "text/html", :locals => { :comment => comment }

View file

@ -185,7 +185,7 @@ class Comment < ActiveRecord::Base
self.markeddown_comment = self.generated_markeddown_comment
end
def delete_for_user(user)
def delete_for_user(user, reason = nil)
Comment.record_timestamps = false
self.is_deleted = true
@ -197,6 +197,11 @@ class Comment < ActiveRecord::Base
m.comment_id = self.id
m.moderator_user_id = user.id
m.action = "deleted comment"
if reason.present?
m.reason = reason
end
m.save
end

View file

@ -75,7 +75,11 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<a class="comment_undeletor">undelete</a>
<% elsif !comment.is_gone? && comment.is_deletable_by_user?(@user) %>
|
<a class="comment_deletor">delete</a>
<% if @user && @user.is_moderator? && @user.id != comment.user_id %>
<a class="comment_moderator">delete</a>
<% else %>
<a class="comment_deletor">delete</a>
<% end %>
<% end %>
<% if @user && !comment.story.is_gone? && !comment.is_gone? %>