diff --git a/app/logical/forum_updater.rb b/app/logical/forum_updater.rb index 84db03410..036a7f0b9 100644 --- a/app/logical/forum_updater.rb +++ b/app/logical/forum_updater.rb @@ -21,9 +21,10 @@ class ForumUpdater end def create_response(body) - forum_topic.posts.create( - :body => body - ) + forum_topic.posts.create({ + :body => body, + :skip_mention_notifications => true + }, :without_protection => true) end def update_title(title_tag) @@ -33,6 +34,6 @@ class ForumUpdater end def update_post(body) - forum_post.update(:body => "#{forum_post.body}\n\nEDIT: #{body}") + forum_post.update({:body => "#{forum_post.body}\n\nEDIT: #{body}", :skip_mention_notifications => true }, :without_protection => true) end end diff --git a/app/logical/mentionable.rb b/app/logical/mentionable.rb index 290c42baf..355fa6362 100644 --- a/app/logical/mentionable.rb +++ b/app/logical/mentionable.rb @@ -9,7 +9,7 @@ module Mentionable @mentionable_options = options message_field = mentionable_option(:message_field) - after_save :queue_mention_messages, if: :"#{message_field}_changed?" + after_save :queue_mention_messages end def mentionable_option(key) @@ -19,6 +19,9 @@ module Mentionable def queue_mention_messages message_field = self.class.mentionable_option(:message_field) + return if !send("#{message_field}_changed?") + return if self.skip_mention_notifications + text = send(message_field) text_was = send("#{message_field}_was") diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 38c4fffe8..293487b68 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -3,6 +3,7 @@ class ForumPost < ApplicationRecord attr_accessible :body, :topic_id, :as => [:member, :builder, :gold, :platinum, :admin, :moderator, :default] attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator] + attr_accessor :skip_mention_notifications # used by `Mentionable::queue_mention_messages` attr_readonly :topic_id belongs_to :creator, :class_name => "User" belongs_to :updater, :class_name => "User" diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 6f21c1a8a..45c467eff 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -134,6 +134,12 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase @post.reload assert_match(/\[REJECTED\]/, @topic.title) end + + should "not send @mention dmails to the approver" do + assert_no_difference("Dmail.count") do + @req.approve!(@admin) + end + end end context "when searching" do