diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 1f979211f..cb5e6ec72 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -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 diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index ffd7d9565..b05758b3a 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -228,9 +228,10 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest assert_redirected_to(@forum_reply) assert_equal(true, @forum_reply.reload.is_deleted?) - assert_match(/updated forum ##{@forum_reply.id}/, ModAction.last.description) + assert_match(/deleted forum ##{@forum_reply.id}/, ModAction.last.description) assert_equal(@forum_reply, ModAction.last.subject) assert_equal(@mod, ModAction.last.creator) + assert_equal("forum_post_delete", ModAction.last.category) end should "not allow users to delete their own posts" do @@ -272,6 +273,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest assert_match(/updated forum ##{@forum_reply.id}/, ModAction.last.description) assert_equal(@forum_reply, ModAction.last.subject) assert_equal(@mod, ModAction.last.creator) + assert_equal("forum_post_update", ModAction.last.category) end should "not allow users to undelete their own posts" do