mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 06:28:03 +08:00
FEATURE: Add setting to disable notifications for topic category edits (#14632)
This commit is contained in:
parent
fb5a062b1f
commit
6275658e3d
|
@ -844,7 +844,7 @@ class Topic < ActiveRecord::Base
|
|||
CategoryUser.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].uniq
|
||||
DB.after_commit do
|
||||
Jobs.enqueue(:notify_category_change, post_id: post.id, notified_user_ids: notified_user_ids)
|
||||
|
|
|
@ -103,6 +103,9 @@ class PostActionNotifier
|
|||
return 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
|
||||
end
|
||||
|
||||
user_ids = []
|
||||
|
||||
|
|
|
@ -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`."
|
||||
|
|
|
@ -2210,6 +2210,9 @@ uncategorized:
|
|||
|
||||
disable_system_edit_notifications: true
|
||||
|
||||
disable_category_edit_notifications:
|
||||
default: false
|
||||
|
||||
notification_consolidation_threshold:
|
||||
default: 3
|
||||
min: 0
|
||||
|
|
|
@ -1529,6 +1529,7 @@ describe Topic do
|
|||
fab!(:category) { Fabricate(:category_with_definition, user: user) }
|
||||
|
||||
describe 'without a previous category' do
|
||||
|
||||
it 'changes the category' do
|
||||
topic.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' do
|
||||
TopicUser.create!(
|
||||
topic_id: topic.id,
|
||||
|
|
|
@ -153,6 +153,25 @@ describe PostActionNotifier do
|
|||
|
||||
end
|
||||
|
||||
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' do
|
||||
let(:lurker) { Fabricate(:user) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user