Fix #4669: Track moderation report status.
* Add ability to mark moderation reports as 'handled' or 'rejected'. * Automatically mark reports as handled when the comment or forum post is deleted. * Send a dmail to the reporter when their report is handled. * Don't show the report notice on comments or forum posts when all reports against it have been handled or rejected. * Add a fix script to mark all existing reports for deleted comments, forum posts, or dmails as handled.
This commit is contained in:
@@ -6,11 +6,13 @@ class Comment < ApplicationRecord
|
||||
belongs_to_updater
|
||||
|
||||
has_many :moderation_reports, as: :model, dependent: :destroy
|
||||
has_many :pending_moderation_reports, -> { pending }, as: :model, class_name: "ModerationReport"
|
||||
has_many :votes, class_name: "CommentVote", dependent: :destroy
|
||||
|
||||
validates :body, presence: true, length: { maximum: 15_000 }, if: :body_changed?
|
||||
|
||||
before_create :autoreport_spam
|
||||
before_save :handle_reports_on_deletion
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_update(:if => ->(rec) {(!rec.is_deleted? || !rec.saved_change_to_is_deleted?) && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.user.name}", :comment_update)
|
||||
@@ -78,6 +80,13 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def handle_reports_on_deletion
|
||||
return unless Pundit.policy!(updater, ModerationReport).update?
|
||||
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
||||
|
||||
moderation_reports.pending.update!(status: :handled)
|
||||
end
|
||||
|
||||
def quoted_response
|
||||
DText.quote(body, creator.name)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user