A platform for community discussion. Free, open, simple.
FIX: tag and category watchers regression (#8336)
Krzysztof Kotlarek69266f60ed83
diff --git a/app/jobs/regular/notify_category_change.rb b/app/jobs/regular/notify_category_change.rbindex bac94a20e07..fbad7582e4a 100644--- a/app/jobs/regular/notify_category_change.rb+++ b/app/jobs/regular/notify_category_change.rb@@ -7,7 +7,7 @@ module Jobsif post&.topic&.visible?post_alerter = PostAlerter.new- post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]))+ post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_tag_watchers: false)post_alerter.notify_first_post_watchers(post, post_alerter.category_watchers(post.topic))endenddiff --git a/app/jobs/regular/notify_tag_change.rb b/app/jobs/regular/notify_tag_change.rbindex fe4f85052b6..dff6769de97 100644--- a/app/jobs/regular/notify_tag_change.rb+++ b/app/jobs/regular/notify_tag_change.rb@@ -7,7 +7,7 @@ module Jobsif post&.topic&.visible?post_alerter = PostAlerter.new- post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]))+ post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_category_watchers: false)post_alerter.notify_first_post_watchers(post, post_alerter.tag_watchers(post.topic))endenddiff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex d71e4b4914d..6784abd2070 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -559,7 +559,7 @@ class PostAlerterendend- def notify_post_users(post, notified)+ def notify_post_users(post, notified, include_category_watchers: true, include_tag_watchers: true)return unless post.topicwarn_if_not_sidekiq@@ -570,8 +570,14 @@ class PostAlerterFROM topic_usersWHERE notification_level = :watchingAND topic_id = :topic_id+ /*category*/+ /*tags*/+ )+ SQL- UNION+ if include_category_watchers+ condition.sub! "/*category*/", <<~SQL+ UNIONSELECT cu.user_idFROM category_users cu@@ -580,14 +586,12 @@ class PostAlerterWHERE cu.notification_level = :watchingAND cu.category_id = :category_idAND tu.user_id IS NULL-- /*tags*/- )- SQL+ SQL+ endtag_ids = post.topic.topic_tags.pluck('topic_tags.tag_id')- if tag_ids.present?+ if include_tag_watchers && tag_ids.present?condition.sub! "/*tags*/", <<~SQLUNIONdiff --git a/spec/jobs/notify_tag_change_spec.rb b/spec/jobs/notify_tag_change_spec.rbindex 3f22cde4009..9d6e0053e3a 100644--- a/spec/jobs/notify_tag_change_spec.rb+++ b/spec/jobs/notify_tag_change_spec.rb@@ -25,4 +25,13 @@ describe ::Jobs::NotifyTagChange doexpect(notification.user_id).to eq(user.id)expect(notification.topic_id).to eq(post.topic_id)end++ it 'doesnt create notification for user watching category' do+ CategoryUser.create!(+ user_id: user.id,+ category_id: post.topic.category_id,+ notification_level: TopicUser.notification_levels[:watching]+ )+ expect { described_class.new.execute(post_id: post.id, notified_user_ids: [regular_user.id]) }.not_to change { Notification.count }+ endend