A platform for community discussion. Free, open, simple.
FIX: Skip job if tag edit notification is disabled (#17508)
Bianca Nenciu4a996825fded
diff --git a/app/jobs/regular/notify_tag_change.rb b/app/jobs/regular/notify_tag_change.rbindex e503287810c..6e45c24d57b 100644--- a/app/jobs/regular/notify_tag_change.rb+++ b/app/jobs/regular/notify_tag_change.rb@@ -3,6 +3,8 @@module Jobsclass NotifyTagChange < ::Jobs::Basedef execute(args)+ return if SiteSetting.disable_tags_edit_notifications+post = Post.find_by(id: args[:post_id])if post&.topic&.visible?diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 7a2ac7f3517..dfa5904d78c 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -113,7 +113,14 @@ class PostRevisorDB.after_commit dopost = tc.topic.ordered_posts.firstnotified_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))+ )+ endendendenddiff --git a/spec/jobs/notify_tag_change_spec.rb b/spec/jobs/notify_tag_change_spec.rbindex e5e2f8a6f61..f5bb3883190 100644--- a/spec/jobs/notify_tag_change_spec.rb+++ b/spec/jobs/notify_tag_change_spec.rb@@ -25,6 +25,22 @@ describe ::Jobs::NotifyTagChange doexpect(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' doCategoryUser.create!(user_id: user.id,