mod actions: record the subject of the mod action.
Add a polymorphic `subject` field that records the subject of the mod action. The subject is the post, user, comment, artist, etc the mod action is for. * The subject for the user ban and unban actions is the user, not the ban itself. * The subject for the user feedback update and deletion actions is the user, not the feedback itself. * The subject for the post undeletion action is the post, not the approval itself. * The subject for the move favorites action is the source post where the favorites were moved from, not the destination post where the favorites were moved to. * The subject for the post permanent delete action is nil, because the post itself is hard deleted. * When a post is permanently deleted, all mod actions related to the post are deleted as well.
This commit is contained in:
@@ -22,6 +22,7 @@ class ForumTopic < ApplicationRecord
|
||||
has_many :bulk_update_requests
|
||||
has_many :tag_aliases
|
||||
has_many :tag_implications
|
||||
has_many :mod_actions, as: :subject, dependent: :destroy
|
||||
|
||||
validates :title, presence: true, length: { maximum: 200 }, if: :title_changed?
|
||||
validates :category_id, inclusion: { in: CATEGORIES.keys }
|
||||
@@ -32,7 +33,7 @@ class ForumTopic < ApplicationRecord
|
||||
after_update :update_posts_on_deletion_or_undeletion
|
||||
after_update :update_original_post
|
||||
after_save(:if => ->(rec) {rec.is_locked? && rec.saved_change_to_is_locked?}) do |rec|
|
||||
ModAction.log("locked forum topic ##{id} (title: #{title})", :forum_topic_lock)
|
||||
ModAction.log("locked forum topic ##{id} (title: #{title})", :forum_topic_lock, subject: self, user: CurrentUser.user)
|
||||
end
|
||||
|
||||
deletable
|
||||
@@ -164,11 +165,11 @@ class ForumTopic < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.log("deleted forum topic ##{id} (title: #{title})", :forum_topic_delete)
|
||||
ModAction.log("deleted forum topic ##{id} (title: #{title})", :forum_topic_delete, subject: self, user: CurrentUser.user)
|
||||
end
|
||||
|
||||
def create_mod_action_for_undelete
|
||||
ModAction.log("undeleted forum topic ##{id} (title: #{title})", :forum_topic_undelete)
|
||||
ModAction.log("undeleted forum topic ##{id} (title: #{title})", :forum_topic_undelete, subject: self, user: CurrentUser.user)
|
||||
end
|
||||
|
||||
def page_for(post_id)
|
||||
|
||||
Reference in New Issue
Block a user