Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't notify editor when category or tag change (#17833)

Bianca Nenciu2db076f9c8c1
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb
index 53942b31d5f..bd5ee865cfd 100644
--- a/app/services/post_alerter.rb
+++ b/app/services/post_alerter.rb
@@ -203,8 +203,8 @@ class PostAlerter
warn_if_not_sidekiq
- # Don't notify the OP
- user_ids -= [post.user_id]
+ # Don't notify the OP and last editor
+ user_ids -= [post.user_id, post.last_editor_id]
users = User.where(id: user_ids).includes(:do_not_disturb_timings)
DiscourseEvent.trigger(:before_create_notifications_for_users, users, post)
diff --git a/spec/jobs/notify_category_change_spec.rb b/spec/jobs/notify_category_change_spec.rb
new file mode 100644
index 00000000000..d218760aed0
--- /dev/null
+++ b/spec/jobs/notify_category_change_spec.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+RSpec.describe ::Jobs::NotifyCategoryChange do
+ fab!(:user) { Fabricate(:user) }
+ fab!(:regular_user) { Fabricate(:trust_level_4) }
+ fab!(:post) { Fabricate(:post, user: regular_user) }
+ fab!(:category) { Fabricate(:category, name: 'test') }
+
+ it "doesn't create notification for the editor who watches new tag" do
+ CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching_first_post], category.id)
+ post.topic.update!(category: category)
+ post.update!(last_editor_id: user.id)
+
+ expect { described_class.new.execute(post_id: post.id, notified_user_ids: []) }.not_to change { Notification.count }
+ end
+end
diff --git a/spec/jobs/notify_tag_change_spec.rb b/spec/jobs/notify_tag_change_spec.rb
index f0fab3d5190..581fd0e251b 100644
--- a/spec/jobs/notify_tag_change_spec.rb
+++ b/spec/jobs/notify_tag_change_spec.rb
@@ -40,6 +40,14 @@ RSpec.describe ::Jobs::NotifyTagChange do
expect { described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id]) }.not_to change { Notification.count }
end
+ it "doesn't create notification for the editor who watches new tag" do
+ TagUser.change(user.id, tag.id, TagUser.notification_levels[:watching_first_post])
+ TopicTag.create!(topic: post.topic, tag: tag)
+ post.update!(last_editor_id: user.id)
+
+ expect { described_class.new.execute(post_id: post.id, notified_user_ids: []) }.not_to change { Notification.count }
+ end
+
it 'doesnt create notification for user watching category' do
CategoryUser.create!(
user_id: user.id,