forum: fix mod action when forum post is deleted.

Fix forum posts logging an "updated forum #1234" mod action instead of a "deleted forum #1234" mod
action when a forum post was deleted.
This commit is contained in:
evazion
2022-11-20 22:24:55 -06:00
parent 1e478ab1b5
commit 80faee67db
2 changed files with 12 additions and 7 deletions

View File

@@ -25,12 +25,7 @@ class ForumPost < ApplicationRecord
after_create :update_topic_updated_at_on_create
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, 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, subject: self, user: forum_post.updater)
end
after_update :create_mod_action
after_create_commit :async_send_discord_notification
deletable
@@ -151,6 +146,14 @@ class ForumPost < ApplicationRecord
topic.response_count -= 1
end
def create_mod_action
if saved_change_to_is_deleted == [false, true] && creator != updater
ModAction.log("deleted #{dtext_shortlink}", :forum_post_delete, subject: self, user: updater)
elsif creator != updater
ModAction.log("updated #{dtext_shortlink}", :forum_post_update, subject: self, user: updater)
end
end
def quoted_response
DText.quote(body, creator.name)
end