Skip to content

Commit

Permalink
Also allow admins to be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
nattsw committed Jan 3, 2024
1 parent d69f108 commit a945423
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ def generate(query_id, query_params, recipients)

def filter_recipients_by_query_access(recipients, query)
recipients.reduce([]) do |names, recipient|
if (group = Group.find_by(name: recipient))
names unless query.query_groups.exists?(group_id: group.id)
names.concat group.users.pluck(:username)
if (group = Group.find_by(name: recipient)) &&
(
group.id == Group::AUTO_GROUPS[:admins] ||
query.query_groups.exists?(group_id: group.id)
)
next names.concat group.users.pluck(:username)
elsif (user = User.find_by(username: recipient))
names unless Guardian.new(user).user_can_access_query?(query)
names << recipient
else
names
next names << recipient if Guardian.new(user).user_can_access_query?(query)
end
next names
end
end

Expand Down

0 comments on commit a945423

Please sign in to comment.