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.
This commit is contained in:
Bianca Nenciu 2022-08-10 18:55:29 +03:00 committed by GitHub
parent e87ca397be
commit 2db076f9c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -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,