From 5f88aafbf697d791707938c9732ec2d86723252a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 27 Sep 2016 14:35:42 +0200 Subject: Improve the logic in AccessRequestsFinder#execute & #execute! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- app/finders/access_requests_finder.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'app/finders') 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 -- cgit v1.2.1