modreports: log modaction when report is handled or rejected.
This commit is contained in:
@@ -32,7 +32,7 @@ class ModerationReportsController < ApplicationController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@moderation_report = authorize ModerationReport.find(params[:id])
|
@moderation_report = authorize ModerationReport.find(params[:id])
|
||||||
@moderation_report.update(permitted_attributes(@moderation_report))
|
@moderation_report.update(updater: CurrentUser.user, **permitted_attributes(@moderation_report))
|
||||||
|
|
||||||
flash.now[:notice] = @moderation_report.valid? ? "Report updated" : @moderation_report.errors.full_messages.join("; ")
|
flash.now[:notice] = @moderation_report.valid? ? "Report updated" : @moderation_report.errors.full_messages.join("; ")
|
||||||
respond_with(@moderation_report)
|
respond_with(@moderation_report)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Comment < ApplicationRecord
|
|||||||
return unless Pundit.policy!(updater, ModerationReport).update?
|
return unless Pundit.policy!(updater, ModerationReport).update?
|
||||||
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
||||||
|
|
||||||
moderation_reports.pending.update!(status: :handled)
|
moderation_reports.pending.update!(status: :handled, updater: updater)
|
||||||
end
|
end
|
||||||
|
|
||||||
def quoted_response
|
def quoted_response
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class ForumPost < ApplicationRecord
|
|||||||
def handle_reports_on_deletion
|
def handle_reports_on_deletion
|
||||||
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
||||||
|
|
||||||
moderation_reports.pending.update!(status: :handled)
|
moderation_reports.pending.update!(status: :handled, updater: updater)
|
||||||
end
|
end
|
||||||
|
|
||||||
def async_send_discord_notification
|
def async_send_discord_notification
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class ModAction < ApplicationRecord
|
|||||||
forum_topic_lock: 206,
|
forum_topic_lock: 206,
|
||||||
forum_post_update: 101,
|
forum_post_update: 101,
|
||||||
forum_post_delete: 102,
|
forum_post_delete: 102,
|
||||||
|
moderation_report_handled: 306,
|
||||||
|
moderation_report_rejected: 307,
|
||||||
tag_alias_create: 120,
|
tag_alias_create: 120,
|
||||||
tag_alias_update: 121, # XXX unused
|
tag_alias_update: 121, # XXX unused
|
||||||
tag_alias_delete: 122,
|
tag_alias_delete: 122,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
class ModerationReport < ApplicationRecord
|
class ModerationReport < ApplicationRecord
|
||||||
MODEL_TYPES = %w[Dmail Comment ForumPost]
|
MODEL_TYPES = %w[Dmail Comment ForumPost]
|
||||||
|
|
||||||
|
attr_accessor :updater
|
||||||
|
|
||||||
belongs_to :model, polymorphic: true
|
belongs_to :model, polymorphic: true
|
||||||
belongs_to :creator, class_name: "User"
|
belongs_to :creator, class_name: "User"
|
||||||
|
|
||||||
@@ -13,6 +15,7 @@ class ModerationReport < ApplicationRecord
|
|||||||
after_create :create_forum_post!
|
after_create :create_forum_post!
|
||||||
after_create :autoban_reported_user
|
after_create :autoban_reported_user
|
||||||
after_save :notify_reporter
|
after_save :notify_reporter
|
||||||
|
after_save :create_modaction
|
||||||
|
|
||||||
scope :dmail, -> { where(model_type: "Dmail") }
|
scope :dmail, -> { where(model_type: "Dmail") }
|
||||||
scope :comment, -> { where(model_type: "Comment") }
|
scope :comment, -> { where(model_type: "Comment") }
|
||||||
@@ -89,6 +92,16 @@ class ModerationReport < ApplicationRecord
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_modaction
|
||||||
|
return unless saved_change_to_status? && status != :pending
|
||||||
|
|
||||||
|
if handled?
|
||||||
|
ModAction.log("handled modreport ##{id}", :moderation_report_handled, updater)
|
||||||
|
elsif rejected?
|
||||||
|
ModAction.log("rejected modreport ##{id}", :moderation_report_rejected, updater)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def reported_user
|
def reported_user
|
||||||
case model
|
case model
|
||||||
when Comment, ForumPost
|
when Comment, ForumPost
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal(true, @comment.reload.is_deleted)
|
assert_equal(true, @comment.reload.is_deleted)
|
||||||
assert_equal(true, report1.reload.handled?)
|
assert_equal(true, report1.reload.handled?)
|
||||||
assert_equal(true, report2.reload.rejected?)
|
assert_equal(true, report2.reload.rejected?)
|
||||||
|
assert_equal(1, ModAction.moderation_report_handled.where(creator: @mod).count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal(true, @forum_post.reload.is_deleted?)
|
assert_equal(true, @forum_post.reload.is_deleted?)
|
||||||
assert_equal(true, report1.reload.handled?)
|
assert_equal(true, report1.reload.handled?)
|
||||||
assert_equal(true, report2.reload.rejected?)
|
assert_equal(true, report2.reload.rejected?)
|
||||||
|
assert_equal(1, ModAction.moderation_report_handled.where(creator: @mod).count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal("handled", report.reload.status)
|
assert_equal("handled", report.reload.status)
|
||||||
assert_equal(true, @user.dmails.received.exists?(from: User.system, title: "Thank you for reporting comment ##{@comment.id}"))
|
assert_equal(true, @user.dmails.received.exists?(from: User.system, title: "Thank you for reporting comment ##{@comment.id}"))
|
||||||
|
assert_equal(true, ModAction.moderation_report_handled.where(creator: @mod).exists?)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow a moderator to mark a moderation report as rejected" do
|
should "allow a moderator to mark a moderation report as rejected" do
|
||||||
@@ -129,6 +130,7 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal("rejected", report.reload.status)
|
assert_equal("rejected", report.reload.status)
|
||||||
assert_equal(false, @user.dmails.received.exists?(from: User.system))
|
assert_equal(false, @user.dmails.received.exists?(from: User.system))
|
||||||
|
assert_equal(true, ModAction.moderation_report_rejected.where(creator: @mod).exists?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user