2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
class AccessRequestsFinder
|
|
|
|
attr_accessor :source
|
|
|
|
|
|
|
|
# Arguments:
|
|
|
|
# source - a Group or Project
|
|
|
|
def initialize(source)
|
|
|
|
@source = source
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(*args)
|
|
|
|
execute!(*args)
|
|
|
|
rescue Gitlab::Access::AccessDeniedError
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute!(current_user)
|
|
|
|
raise Gitlab::Access::AccessDeniedError unless can_see_access_requests?(current_user)
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
if Feature.enabled?(:project_members_index_by_project_namespace, source)
|
|
|
|
source.namespace_requesters
|
|
|
|
else
|
|
|
|
source.requesters
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_see_access_requests?(current_user)
|
2023-01-13 00:05:48 +05:30
|
|
|
source && Ability.allowed?(current_user, :admin_member_access_request, source)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|