From 2db076f9c8c1dbcd9045ae5a3d650637e191b8ca Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 10 Aug 2022 18:55:29 +0300 Subject: [PATCH] FIX: Don't notify editor when category or tag change (#17833) When a user was editing a topic they were also receiving a notification if they were watching any of the new category or tags. --- app/services/post_alerter.rb | 4 ++-- spec/jobs/notify_category_change_spec.rb | 16 ++++++++++++++++ spec/jobs/notify_tag_change_spec.rb | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 spec/jobs/notify_category_change_spec.rb 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,