A platform for community discussion. Free, open, simple.
FEATURE: Add setting to disable notifications for topic category edits (#14632)
Jean6275658e3d3f
diff --git a/app/models/topic.rb b/app/models/topic.rbindex 4c9f0f84f89..5f807a7dfef 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -844,7 +844,7 @@ class Topic < ActiveRecord::BaseCategoryUser.auto_watch(category_id: new_category.id, topic_id: self.id)CategoryUser.auto_track(category_id: new_category.id, topic_id: self.id)- if post = self.ordered_posts.first+ if !SiteSetting.disable_category_edit_notifications && (post = self.ordered_posts.first)notified_user_ids = [post.user_id, post.last_editor_id].uniqDB.after_commit doJobs.enqueue(:notify_category_change, post_id: post.id, notified_user_ids: notified_user_ids)diff --git a/app/services/post_action_notifier.rb b/app/services/post_action_notifier.rbindex 881af4953f9..f58b784b503 100644--- a/app/services/post_action_notifier.rb+++ b/app/services/post_action_notifier.rb@@ -103,6 +103,9 @@ class PostActionNotifierreturn if post.topic.blank?return if post.topic.private_message?return if SiteSetting.disable_system_edit_notifications && post_revision.user_id == Discourse::SYSTEM_USER_ID+ if SiteSetting.disable_category_edit_notifications && post_revision.modifications&.dig("category_id").present?+ return+ enduser_ids = []diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 43d4c4384c9..da3b53354a7 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2129,6 +2129,8 @@ en:disable_system_edit_notifications: "Disables edit notifications by the system user when 'download_remote_images_to_local' is active."+ disable_category_edit_notifications: "Disable category edit notifications on topics."+notification_consolidation_threshold: "Number of liked or membership request notifications received before the notifications are consolidated into a single one. Set to 0 to disable."likes_notification_consolidation_window_mins: "Duration in minutes where liked notifications are consolidated into a single notification once the threshold has been reached. The threshold can be configured via `SiteSetting.notification_consolidation_threshold`."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 5a5ff881296..b7c97efd015 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -2210,6 +2210,9 @@ uncategorized:disable_system_edit_notifications: true+ disable_category_edit_notifications:+ default: false+notification_consolidation_threshold:default: 3min: 0diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex cbc5bfba370..64d599f0196 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -1529,6 +1529,7 @@ describe Topic dofab!(:category) { Fabricate(:category_with_definition, user: user) }describe 'without a previous category' do+it 'changes the category' dotopic.change_category_to_id(category.id)category.reload@@ -1620,6 +1621,16 @@ describe Topic do).exists?).to eq(true)end+ it 'should not generate a notification if SiteSetting.disable_category_edit_notifications is enabled' do+ SiteSetting.disable_category_edit_notifications = true++ expect do+ topic.change_category_to_id(new_category.id)+ end.to change { Notification.count }.by(0)++ expect(topic.category_id).to eq(new_category.id)+ end+it 'should generate the modified notification for the topic if already seen' doTopicUser.create!(topic_id: topic.id,diff --git a/spec/services/post_action_notifier_spec.rb b/spec/services/post_action_notifier_spec.rbindex f1bf3e08de9..fbdbd674e14 100644--- a/spec/services/post_action_notifier_spec.rb+++ b/spec/services/post_action_notifier_spec.rb@@ -153,6 +153,25 @@ describe PostActionNotifier doend+ context "category edit notifications are disabled" do+ it 'notifies a user of the revision made by another user' do+ SiteSetting.disable_category_edit_notifications = false++ expect {+ post.revise(evil_trout, category_id: Fabricate(:category).id)+ }.to change(post.user.notifications, :count).by(1)+ end++ it 'does not notify a user of the revision made by the system user' do+ SiteSetting.disable_category_edit_notifications = true++ expect {+ post.revise(evil_trout, category_id: Fabricate(:category).id)+ }.not_to change(post.user.notifications, :count)+ end++ end+context 'when using plugin API to add custom recipients' dolet(:lurker) { Fabricate(:user) }