FEATURE: Admins should be able to view PMs of any group.

This commit is contained in:
Guo Xiang Tan
2018-03-19 14:12:01 +08:00
parent 7fad30dacc
commit ec57ca54b5
2 changed files with 56 additions and 5 deletions

View File

@@ -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})")