2016-07-28 13:38:32 -04:00
|
|
|
class AccessRequestsFinder
|
|
|
|
attr_accessor :source
|
|
|
|
|
|
|
|
# Arguments:
|
|
|
|
# source - a Group or Project
|
|
|
|
def initialize(source)
|
|
|
|
@source = source
|
|
|
|
end
|
|
|
|
|
2016-09-27 08:35:42 -04:00
|
|
|
def execute(*args)
|
|
|
|
execute!(*args)
|
|
|
|
rescue Gitlab::Access::AccessDeniedError
|
|
|
|
[]
|
2016-07-28 13:38:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute!(current_user)
|
2016-09-27 08:35:42 -04:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless can_see_access_requests?(current_user)
|
|
|
|
|
|
|
|
source.requesters
|
2016-07-28 13:38:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-27 08:35:42 -04:00
|
|
|
def can_see_access_requests?(current_user)
|
2016-09-27 09:52:30 -04:00
|
|
|
source && Ability.allowed?(current_user, :"admin_#{source.class.to_s.underscore}", source)
|
2016-07-28 13:38:32 -04:00
|
|
|
end
|
|
|
|
end
|