diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index ab86e75915b..63e33aa67b3 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -298,6 +298,8 @@ class PostAlerter # Make sure the user can see the post return unless Guardian.new(user).can_see?(post) + return if user.staged? && post.topic.category&.mailinglist_mirror? + notifier_id = opts[:user_id] || post.user_id # xxxxx look at revision history # apply muting here diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 74c41d9a7a9..c500ce2d1e3 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -627,6 +627,21 @@ describe PostAlerter do expect(dave.notifications.count).to eq(1) expect(erin.notifications.count).to eq(1) end + + it "does not send email notifications to staged users when notification originates in mailinglist mirror category" do + category = Fabricate(:mailinglist_mirror_category) + topic = Fabricate(:topic, category: category) + user = Fabricate(:staged) + post = Fabricate(:post, user: user, topic: topic) + reply = Fabricate(:post, topic: topic, reply_to_post_number: 1) + + NotificationEmailer.expects(:process_notification).never + expect { PostAlerter.post_created(reply) }.to change(user.notifications, :count).by(0) + + category.mailinglist_mirror = false + NotificationEmailer.expects(:process_notification).once + expect { PostAlerter.post_created(reply) }.to change(user.notifications, :count).by(1) + end end context "watching" do