BigW Consortium Gitlab

access_requests_finder.rb 562 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
class AccessRequestsFinder
  attr_accessor :source

  # Arguments:
  #   source - a Group or Project
  def initialize(source)
    @source = source
  end

10 11 12 13
  def execute(*args)
    execute!(*args)
  rescue Gitlab::Access::AccessDeniedError
    []
14 15 16
  end

  def execute!(current_user)
17 18 19
    raise Gitlab::Access::AccessDeniedError unless can_see_access_requests?(current_user)

    source.requesters
20 21 22 23
  end

  private

24
  def can_see_access_requests?(current_user)
25
    source && Ability.allowed?(current_user, :"admin_#{source.class.to_s.underscore}", source)
26 27
  end
end