A platform for community discussion. Free, open, simple.
FIX: Allow "watching first post" notification to fire when tags edit notifications are disabled (#37935)
Natalie Tay96c4e8d994a2
diff --git a/app/jobs/regular/notify_tag_change.rb b/app/jobs/regular/notify_tag_change.rbindex 0038dba193c..b77446b7297 100644--- a/app/jobs/regular/notify_tag_change.rb+++ b/app/jobs/regular/notify_tag_change.rb@@ -3,21 +3,21 @@module Jobsclass NotifyTagChange < ::Jobs::Basedef execute(args)- return if SiteSetting.disable_tags_edit_notifications && !args[:force]-post = Post.find_by(id: args[:post_id])+ return if !post&.topic&.visible?++ post_alerter = PostAlerter.new+ post_alerter.notify_first_post_watchers(post, post_alerter.tag_watchers(post.topic))++ return if SiteSetting.disable_tags_edit_notifications && !args[:force]- if post&.topic&.visible?- post_alerter = PostAlerter.new- post_alerter.notify_post_users(- post,- User.where(id: args[:notified_user_ids]),- group_ids: all_tags_in_hidden_groups?(args) ? tag_group_ids(args) : nil,- include_topic_watchers: !post.topic.private_message?,- include_category_watchers: false,- )- post_alerter.notify_first_post_watchers(post, post_alerter.tag_watchers(post.topic))- end+ post_alerter.notify_post_users(+ post,+ User.where(id: args[:notified_user_ids]),+ group_ids: all_tags_in_hidden_groups?(args) ? tag_group_ids(args) : nil,+ include_topic_watchers: !post.topic.private_message?,+ include_category_watchers: false,+ )endprivatediff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 4ef4b3258af..ae85f470b05 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -69,9 +69,7 @@ class PostRevisordiff_tags = added_tags | removed_tagsif diff_tags.present?- if !SiteSetting.disable_tags_edit_notifications- Jobs.enqueue(:notify_tag_change, post_id: post.id, notified_user_ids:, diff_tags:)- end+ Jobs.enqueue(:notify_tag_change, post_id: post.id, notified_user_ids:, diff_tags:)PostRevisor.create_small_action_for_tag_changes(topic: t,diff --git a/spec/jobs/notify_tag_change_spec.rb b/spec/jobs/notify_tag_change_spec.rbindex 0c01967adc2..7695d006fed 100644--- a/spec/jobs/notify_tag_change_spec.rb+++ b/spec/jobs/notify_tag_change_spec.rb@@ -23,7 +23,7 @@ RSpec.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+ it "doesn't create tag edit notifications if tags edit notifications are disabled" doSiteSetting.disable_tags_edit_notifications = trueTagUser.create!(@@ -38,7 +38,37 @@ RSpec.describe ::Jobs::NotifyTagChange do}.not_to change { Notification.count }end- it "doesn't create notification for the editor who watches new tag" do+ it "creates watching_first_post notification when watched tag is added" do+ TagUser.change(user.id, tag.id, TagUser.notification_levels[:watching_first_post])+ TopicTag.create!(topic: post.topic, tag: tag)++ expect {+ described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id])+ }.to change {+ Notification.where(+ user_id: user.id,+ notification_type: Notification.types[:watching_first_post],+ ).count+ }.by(1)+ end++ it "creates watching_first_post notification even when tag edit notifications are disabled" do+ SiteSetting.disable_tags_edit_notifications = true++ TagUser.change(user.id, tag.id, TagUser.notification_levels[:watching_first_post])+ TopicTag.create!(topic: post.topic, tag: tag)++ expect {+ described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id])+ }.to change {+ Notification.where(+ user_id: user.id,+ notification_type: Notification.types[:watching_first_post],+ ).count+ }.by(1)+ end++ it "doesn't create watching_first_post notification for the editor who watches new tag" doTagUser.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)diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 143137c5bc8..49919e6072e 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -2220,6 +2220,22 @@ RSpec.describe PostAlerter do).to eq(1)end+ it "triggers a watching_first_post notification even when tag edit notifications are disabled" do+ SiteSetting.disable_tags_edit_notifications = true++ expect {+ PostRevisor.new(post).revise!(+ Fabricate(:user, refresh_auto_groups: true),+ tags: [other_tag.name, watched_tag.name],+ )+ }.to change {+ user+ .notifications+ .where(notification_type: Notification.types[:watching_first_post])+ .count+ }.by(1)+ end+it "doesn't trigger a notification if topic is unlisted" dopost.topic.update_column(:visible, false)