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:
evazion
2022-09-25 01:05:50 -05:00
parent 9026875776
commit 34057b25e1
38 changed files with 183 additions and 71 deletions

View File

@@ -11,6 +11,7 @@ class ForumPost < ApplicationRecord
has_many :moderation_reports, as: :model
has_many :pending_moderation_reports, -> { pending }, as: :model, class_name: "ModerationReport"
has_many :votes, class_name: "ForumPostVote"
has_many :mod_actions, as: :subject, dependent: :destroy
has_one :tag_alias
has_one :tag_implication
has_one :bulk_update_request
@@ -25,10 +26,10 @@ class ForumPost < ApplicationRecord
after_update :update_topic_updated_at_on_update_for_original_posts
after_destroy :update_topic_updated_at_on_destroy
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |forum_post|
ModAction.log("updated #{forum_post.dtext_shortlink}", :forum_post_update, forum_post.updater)
ModAction.log("updated #{forum_post.dtext_shortlink}", :forum_post_update, subject: self, user: forum_post.updater)
end
after_destroy(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |forum_post|
ModAction.log("deleted #{forum_post.dtext_shortlink}", :forum_post_delete, forum_post.updater)
ModAction.log("deleted #{forum_post.dtext_shortlink}", :forum_post_delete, subject: self, user: forum_post.updater)
end
after_create_commit :async_send_discord_notification