modreports: log modaction when report is handled or rejected.

This commit is contained in:
evazion
2022-01-20 21:28:29 -06:00
parent c8d27c2719
commit 5fd0d498a4
8 changed files with 22 additions and 3 deletions

View File

@@ -3,6 +3,8 @@
class ModerationReport < ApplicationRecord
MODEL_TYPES = %w[Dmail Comment ForumPost]
attr_accessor :updater
belongs_to :model, polymorphic: true
belongs_to :creator, class_name: "User"
@@ -13,6 +15,7 @@ class ModerationReport < ApplicationRecord
after_create :create_forum_post!
after_create :autoban_reported_user
after_save :notify_reporter
after_save :create_modaction
scope :dmail, -> { where(model_type: "Dmail") }
scope :comment, -> { where(model_type: "Comment") }
@@ -89,6 +92,16 @@ class ModerationReport < ApplicationRecord
EOS
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
case model
when Comment, ForumPost