mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 10:24:49 +08:00
FIX: Do not notify admins watching PM tags (#18103)
Admins received notifications if a PM was tagged with a tag they watched even if they were not invited to the PM.
This commit is contained in:
parent
446eb40bb6
commit
6564d04e0d
|
@ -170,6 +170,8 @@ class PostAlerter
|
||||||
|
|
||||||
if topic.present?
|
if topic.present?
|
||||||
watchers = category_watchers(topic) + tag_watchers(topic) + group_watchers(topic)
|
watchers = category_watchers(topic) + tag_watchers(topic) + group_watchers(topic)
|
||||||
|
# Notify only users who can see the topic
|
||||||
|
watchers &= topic.all_allowed_users.pluck(:id) if post.topic.private_message?
|
||||||
notify_first_post_watchers(post, watchers)
|
notify_first_post_watchers(post, watchers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2004,4 +2004,21 @@ RSpec.describe PostAlerter do
|
||||||
expect(liked_notification.data_hash[:custom_key]).to eq(custom_data)
|
expect(liked_notification.data_hash[:custom_key]).to eq(custom_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not create notifications for PMs if not invited" do
|
||||||
|
SiteSetting.pm_tags_allowed_for_groups = "#{Group::AUTO_GROUPS[:everyone]}"
|
||||||
|
watching_first_post_tag = Fabricate(:tag)
|
||||||
|
TagUser.change(admin.id, watching_first_post_tag.id, TagUser.notification_levels[:watching_first_post])
|
||||||
|
watching_tag = Fabricate(:tag)
|
||||||
|
TagUser.change(admin.id, watching_tag.id, TagUser.notification_levels[:watching])
|
||||||
|
|
||||||
|
post = create_post(tags: [watching_first_post_tag.name, watching_tag.name], archetype: Archetype.private_message, target_usernames: "#{evil_trout.username}")
|
||||||
|
expect { PostAlerter.new.after_save_post(post, true) }.to change { Notification.count }.by(1)
|
||||||
|
|
||||||
|
notification = Notification.last
|
||||||
|
expect(notification.user).to eq(evil_trout)
|
||||||
|
expect(notification.notification_type).to eq(Notification.types[:private_message])
|
||||||
|
expect(notification.topic).to eq(post.topic)
|
||||||
|
expect(notification.post_number).to eq(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user