mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 10:15:37 +08:00
FEATURE: Admins should be able to view PMs of any group.
This commit is contained in:
parent
7fad30dacc
commit
ec57ca54b5
@ -434,11 +434,21 @@ class TopicQuery
|
|||||||
|
|
||||||
if type == :group
|
if type == :group
|
||||||
result = result.includes(:allowed_users)
|
result = result.includes(:allowed_users)
|
||||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_groups
|
result = result.where("
|
||||||
WHERE group_id IN (
|
topics.id IN (
|
||||||
SELECT group_id FROM group_users WHERE user_id = #{user.id.to_i}) AND
|
SELECT topic_id FROM topic_allowed_groups
|
||||||
group_id IN (SELECT id FROM groups WHERE name ilike ?)
|
WHERE (
|
||||||
)", @options[:group_name])
|
group_id IN (
|
||||||
|
SELECT group_id
|
||||||
|
FROM group_users
|
||||||
|
WHERE user_id = #{user.id.to_i}
|
||||||
|
OR #{user.staff?}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
AND group_id IN (SELECT id FROM groups WHERE name ilike ?)
|
||||||
|
)",
|
||||||
|
@options[:group_name]
|
||||||
|
)
|
||||||
elsif type == :user
|
elsif type == :user
|
||||||
result = result.includes(:allowed_users)
|
result = result.includes(:allowed_users)
|
||||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_users WHERE user_id = #{user.id.to_i})")
|
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_users WHERE user_id = #{user.id.to_i})")
|
||||||
|
@ -940,4 +940,45 @@ describe TopicQuery do
|
|||||||
expect(topics).to contain_exactly(topic1, topic2, topic6)
|
expect(topics).to contain_exactly(topic1, topic2, topic6)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#list_private_messages_group' do
|
||||||
|
let(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
|
let!(:group_message) do
|
||||||
|
Fabricate(:private_message_topic,
|
||||||
|
allowed_groups: [group],
|
||||||
|
topic_allowed_users: [
|
||||||
|
Fabricate.build(:topic_allowed_user, user: Fabricate(:user)),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
group.add(creator)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the right list for a group user' do
|
||||||
|
topics = TopicQuery.new(nil, group_name: group.name)
|
||||||
|
.list_private_messages_group(creator)
|
||||||
|
.topics
|
||||||
|
|
||||||
|
expect(topics).to contain_exactly(group_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the right list for an admin not part of the group' do
|
||||||
|
topics = TopicQuery.new(nil, group_name: group.name)
|
||||||
|
.list_private_messages_group(Fabricate(:admin))
|
||||||
|
.topics
|
||||||
|
|
||||||
|
expect(topics).to contain_exactly(group_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the right list for a user not part of the group' do
|
||||||
|
topics = TopicQuery.new(nil, group_name: group.name)
|
||||||
|
.list_private_messages_group(Fabricate(:user))
|
||||||
|
.topics
|
||||||
|
|
||||||
|
expect(topics).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user