BigW Consortium Gitlab

Commit 5f88aafb by Rémy Coutable

Improve the logic in AccessRequestsFinder#execute & #execute!

Signed-off-by: 's avatarRémy Coutable <remy@rymai.me>
parent 924a6b7d
...@@ -7,23 +7,21 @@ class AccessRequestsFinder ...@@ -7,23 +7,21 @@ class AccessRequestsFinder
@source = source @source = source
end end
def execute(current_user, raise_error: false) def execute(*args)
if cannot_see_access_requests?(current_user) execute!(*args)
raise Gitlab::Access::AccessDeniedError if raise_error rescue Gitlab::Access::AccessDeniedError
[]
return []
end
source.requesters
end end
def execute!(current_user) def execute!(current_user)
execute(current_user, raise_error: true) raise Gitlab::Access::AccessDeniedError unless can_see_access_requests?(current_user)
source.requesters
end end
private private
def cannot_see_access_requests?(current_user) def can_see_access_requests?(current_user)
!source || !current_user || !current_user.can?(:"admin_#{source.class.to_s.underscore}", source) source && current_user && current_user.can?(:"admin_#{source.class.to_s.underscore}", source)
end end
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