Commit 5f88aafb authored by Rémy Coutable's avatar Rémy Coutable

Improve the logic in AccessRequestsFinder#execute & #execute!

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 924a6b7d
......@@ -7,23 +7,21 @@ class AccessRequestsFinder
@source = source
end
def execute(current_user, raise_error: false)
if cannot_see_access_requests?(current_user)
raise Gitlab::Access::AccessDeniedError if raise_error
return []
end
source.requesters
def execute(*args)
execute!(*args)
rescue Gitlab::Access::AccessDeniedError
[]
end
def execute!(current_user)
execute(current_user, raise_error: true)
raise Gitlab::Access::AccessDeniedError unless can_see_access_requests?(current_user)
source.requesters
end
private
def cannot_see_access_requests?(current_user)
!source || !current_user || !current_user.can?(:"admin_#{source.class.to_s.underscore}", source)
def can_see_access_requests?(current_user)
source && current_user && current_user.can?(:"admin_#{source.class.to_s.underscore}", source)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment