FIX: Skip job if tag edit notification is disabled ()

Previous commit did not schedule any more new jobs, but the jobs in
queue could still create notifications.

Follow up to commit e8d802eb86bb4c9fda140422325e80b21541e33e.
This commit is contained in:
Bianca Nenciu 2022-07-15 15:36:27 +03:00 committed by GitHub
parent f774083016
commit 4a996825fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

@ -3,6 +3,8 @@
module Jobs
class NotifyTagChange < ::Jobs::Base
def execute(args)
return if SiteSetting.disable_tags_edit_notifications
post = Post.find_by(id: args[:post_id])
if post&.topic&.visible?

@ -113,7 +113,14 @@ class PostRevisor
DB.after_commit do
post = tc.topic.ordered_posts.first
notified_user_ids = [post.user_id, post.last_editor_id].uniq
Jobs.enqueue(:notify_tag_change, post_id: post.id, notified_user_ids: notified_user_ids, diff_tags: ((tags - prev_tags) | (prev_tags - tags))) if !SiteSetting.disable_tags_edit_notifications
if !SiteSetting.disable_tags_edit_notifications
Jobs.enqueue(
:notify_tag_change,
post_id: post.id,
notified_user_ids: notified_user_ids,
diff_tags: ((tags - prev_tags) | (prev_tags - tags))
)
end
end
end
end

@ -25,6 +25,22 @@ describe ::Jobs::NotifyTagChange do
expect(notification.notification_type).to eq(Notification.types[:posted])
end
it "doesn't create notifications if tags edit notifications are disabled" do
SiteSetting.disable_tags_edit_notifications = true
TagUser.create!(
user_id: user.id,
tag_id: tag.id,
notification_level: NotificationLevels.topic_levels[:watching]
)
TopicTag.create!(
topic_id: post.topic.id,
tag_id: tag.id
)
expect { described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id]) }.not_to change { Notification.count }
end
it 'doesnt create notification for user watching category' do
CategoryUser.create!(
user_id: user.id,