summaryrefslogtreecommitdiff
path: root/app/finders/access_requests_finder.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-09-27 14:35:42 +0200
committerRémy Coutable <remy@rymai.me>2016-09-28 08:46:59 +0200
commit5f88aafbf697d791707938c9732ec2d86723252a (patch)
treedb62c121772820183a356e37aa59b5b737f9a3a0 /app/finders/access_requests_finder.rb
parent924a6b7d33a245845071894de8d46d77bd44b52e (diff)
downloadgitlab-ce-5f88aafbf697d791707938c9732ec2d86723252a.tar.gz
Improve the logic in AccessRequestsFinder#execute & #execute!
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/finders/access_requests_finder.rb')
-rw-r--r--app/finders/access_requests_finder.rb20
1 files changed, 9 insertions, 11 deletions
diff --git a/app/finders/access_requests_finder.rb b/app/finders/access_requests_finder.rb
index 78fb7627741..79b0ba39e2c 100644
--- a/app/finders/access_requests_finder.rb
+++ b/app/finders/access_requests_finder.rb
@@ -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