A platform for community discussion. Free, open, simple.
FIX: Send notification emails for staff-coloured posts (#37712)
Régis Hanolcf20b1c4309c
diff --git a/app/services/notification_emailer.rb b/app/services/notification_emailer.rbindex 139a1f4bfb6..60150b3da8f 100644--- a/app/services/notification_emailer.rb+++ b/app/services/notification_emailer.rb@@ -75,7 +75,7 @@ class NotificationEmailerprivate- EMAILABLE_POST_TYPES = Set.new [Post.types[:regular], Post.types[:whisper]]+ EMAILABLE_POST_TYPES = Post.types.values_at(:regular, :whisper, :moderator_action).to_setdef enqueue(type, delay = default_delay)return if notification.user.user_option.email_level == UserOption.email_level_types[:never]diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex d68c2373442..d3bea02b5dc 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -720,14 +720,11 @@ class PostAlerterenddef expand_here_mention(post, exclude_ids: nil)- posts = Post.where(topic_id: post.topic_id)- posts = posts.where.not(user_id: exclude_ids) if exclude_ids.present?+ post_type = [Post.types[:regular], Post.types[:moderator_action]]+ post_type << Post.types[:whisper] if post.user.staff?- if post.user.staff?- posts = posts.where(post_type: [Post.types[:regular], Post.types[:whisper]])- else- posts = posts.where(post_type: Post.types[:regular])- end+ posts = Post.where(topic_id: post.topic_id, post_type:)+ posts = posts.where.not(user_id: exclude_ids) if exclude_ids.present?User.real.where(id: posts.select(:user_id)).limit(SiteSetting.max_here_mentioned)enddiff --git a/spec/services/notification_emailer_spec.rb b/spec/services/notification_emailer_spec.rbindex c4667cedc83..a91660dff56 100644--- a/spec/services/notification_emailer_spec.rb+++ b/spec/services/notification_emailer_spec.rb@@ -90,6 +90,16 @@ RSpec.describe NotificationEmailer doendend+ context "with a moderator action post" do+ it "enqueues a job" do+ Post.any_instance.expects(:post_type).returns(Post.types[:moderator_action])++ expect_enqueued_with(job: :user_email, args: { type: type }) do+ NotificationEmailer.process_notification(notification, no_delay: no_delay)+ end+ end+ end+context "with a small action" doit "doesn't enqueue a job" doPost.any_instance.expects(:post_type).returns(Post.types[:small_action])diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex f862432ed30..143137c5bc8 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -792,6 +792,15 @@ RSpec.describe PostAlerter do).by(1).and change(post3.user.notifications, :count).by(1)end+ it "notifies users who posted with staff colour" do+ post2 = Fabricate(:post, topic: topic, post_type: Post.types[:moderator_action])++ expect { post }.to change(other_post.user.notifications, :count).by(1).and change(+ post2.user.notifications,+ :count,+ ).by(1)+ end+it "notifies only last max_here_mentioned users" doSiteSetting.max_here_mentioned = 23.times { Fabricate(:post, topic: topic) }