From 28bbc9c8f798d0163fc968730b73ea3493c90fe5 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 10 Feb 2016 08:57:38 -0600 Subject: [PATCH] moderators have to provide a reason for deleting others' comments --- app/assets/javascripts/application.js.erb | 12 ++++++++++++ app/controllers/comments_controller.rb | 2 +- app/models/comment.rb | 7 ++++++- app/views/comments/_comment.html.erb | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 76b3b83..c345d12 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -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"); diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5a8b3f8..1838008 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 } diff --git a/app/models/comment.rb b/app/models/comment.rb index 332a8a5..36b34a1 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 1ee424c..80ce1a9 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -75,7 +75,11 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? undelete <% elsif !comment.is_gone? && comment.is_deletable_by_user?(@user) %> | - delete + <% if @user && @user.is_moderator? && @user.id != comment.user_id %> + delete + <% else %> + delete + <% end %> <% end %> <% if @user && !comment.story.is_gone? && !comment.is_gone? %>