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
|
||||
result = result.includes(:allowed_users)
|
||||
result = result.where("topics.id IN (SELECT topic_id FROM topic_allowed_groups
|
||||
WHERE group_id IN (
|
||||
SELECT group_id FROM group_users WHERE user_id = #{user.id.to_i}) AND
|
||||
group_id IN (SELECT id FROM groups WHERE name ilike ?)
|
||||
)", @options[:group_name])
|
||||
result = result.where("
|
||||
topics.id IN (
|
||||
SELECT topic_id FROM topic_allowed_groups
|
||||
WHERE (
|
||||
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
|
||||
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})")
|
||||
|
|
|
@ -940,4 +940,45 @@ describe TopicQuery do
|
|||
expect(topics).to contain_exactly(topic1, topic2, topic6)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue