mirror of
https://github.com/discourse/discourse.git
synced 2024-12-20 18:36:54 +08:00
FIX: whisper's presence channels (#30097)
In 0993273
we introduced the `whisper_allowed_group_ids` to allow whispers to more users than "staff".
The presence plugin hadn't been updated to account for this change.
This commit is contained in:
parent
ad7a64b983
commit
3e7f0867ea
|
@ -31,7 +31,7 @@ after_initialize do
|
||||||
config
|
config
|
||||||
elsif topic_id = channel_name[%r{/discourse-presence/whisper/(\d+)}, 1]
|
elsif topic_id = channel_name[%r{/discourse-presence/whisper/(\d+)}, 1]
|
||||||
Topic.find(topic_id) # Just ensure it exists
|
Topic.find(topic_id) # Just ensure it exists
|
||||||
PresenceChannel::Config.new(allowed_group_ids: [::Group::AUTO_GROUPS[:staff]])
|
PresenceChannel::Config.new(allowed_group_ids: SiteSetting.whispers_allowed_groups_map)
|
||||||
elsif post_id = channel_name[%r{/discourse-presence/edit/(\d+)}, 1]
|
elsif post_id = channel_name[%r{/discourse-presence/edit/(\d+)}, 1]
|
||||||
post = Post.find(post_id)
|
post = Post.find(post_id)
|
||||||
topic = Topic.find(post.topic_id)
|
topic = Topic.find(post.topic_id)
|
||||||
|
@ -39,8 +39,14 @@ after_initialize do
|
||||||
config = PresenceChannel::Config.new
|
config = PresenceChannel::Config.new
|
||||||
config.allowed_group_ids = [::Group::AUTO_GROUPS[:staff]]
|
config.allowed_group_ids = [::Group::AUTO_GROUPS[:staff]]
|
||||||
|
|
||||||
# Locked and whisper posts are staff only
|
# Locked posts are staff only
|
||||||
next config if post.locked? || post.whisper?
|
next config if post.locked?
|
||||||
|
|
||||||
|
# Whispers posts are for allowed whisper groups
|
||||||
|
if post.whisper?
|
||||||
|
config.allowed_group_ids += SiteSetting.whispers_allowed_groups_map
|
||||||
|
next config
|
||||||
|
end
|
||||||
|
|
||||||
config.allowed_user_ids = [post.user_id]
|
config.allowed_user_ids = [post.user_id]
|
||||||
|
|
||||||
|
@ -55,8 +61,8 @@ after_initialize do
|
||||||
config.allowed_group_ids += SiteSetting.edit_wiki_post_allowed_groups_map
|
config.allowed_group_ids += SiteSetting.edit_wiki_post_allowed_groups_map
|
||||||
end
|
end
|
||||||
|
|
||||||
if !topic.private_message? && SiteSetting.edit_all_post_groups.present?
|
if !topic.private_message? && SiteSetting.edit_all_post_groups_map.present?
|
||||||
config.allowed_group_ids += SiteSetting.edit_all_post_groups.split("|").map(&:to_i)
|
config.allowed_group_ids += SiteSetting.edit_all_post_groups_map
|
||||||
end
|
end
|
||||||
|
|
||||||
if SiteSetting.enable_category_group_moderation? && topic.category
|
if SiteSetting.enable_category_group_moderation? && topic.category
|
||||||
|
|
|
@ -118,15 +118,20 @@ RSpec.describe "discourse-presence" do
|
||||||
it "handles permissions for whispers" do
|
it "handles permissions for whispers" do
|
||||||
c = PresenceChannel.new("/discourse-presence/whisper/#{public_topic.id}")
|
c = PresenceChannel.new("/discourse-presence/whisper/#{public_topic.id}")
|
||||||
expect(c.config.public).to eq(false)
|
expect(c.config.public).to eq(false)
|
||||||
expect(c.config.allowed_group_ids).to contain_exactly(Group::AUTO_GROUPS[:staff])
|
expect(c.config.allowed_group_ids).to contain_exactly(
|
||||||
|
*SiteSetting.whispers_allowed_groups_map,
|
||||||
|
)
|
||||||
expect(c.config.allowed_user_ids).to eq(nil)
|
expect(c.config.allowed_user_ids).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only allows staff when editing whispers" do
|
it "correctly allows whisperers when editing whispers" do
|
||||||
p = Fabricate(:whisper, topic: public_topic, user: admin)
|
p = Fabricate(:whisper, topic: public_topic, user: admin)
|
||||||
c = PresenceChannel.new("/discourse-presence/edit/#{p.id}")
|
c = PresenceChannel.new("/discourse-presence/edit/#{p.id}")
|
||||||
expect(c.config.public).to eq(false)
|
expect(c.config.public).to eq(false)
|
||||||
expect(c.config.allowed_group_ids).to contain_exactly(Group::AUTO_GROUPS[:staff])
|
expect(c.config.allowed_group_ids).to contain_exactly(
|
||||||
|
Group::AUTO_GROUPS[:staff],
|
||||||
|
*SiteSetting.whispers_allowed_groups_map,
|
||||||
|
)
|
||||||
expect(c.config.allowed_user_ids).to eq(nil)
|
expect(c.config.allowed_user_ids).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user