2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
2016-09-29 09:46:39 +05:30
|
|
|
module Auth
|
2021-10-27 15:23:28 +05:30
|
|
|
class Result
|
|
|
|
attr_reader :actor, :project, :type, :authentication_abilities
|
|
|
|
|
|
|
|
def initialize(actor, project, type, authentication_abilities)
|
|
|
|
@actor = actor
|
|
|
|
@project = project
|
|
|
|
@type = type
|
|
|
|
@authentication_abilities = authentication_abilities
|
|
|
|
end
|
|
|
|
|
|
|
|
EMPTY = self.new(nil, nil, nil, nil).freeze
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def ci?(for_project)
|
|
|
|
type == :ci &&
|
|
|
|
project &&
|
|
|
|
project == for_project
|
|
|
|
end
|
|
|
|
|
|
|
|
def lfs_deploy_token?(for_project)
|
|
|
|
type == :lfs_deploy_token &&
|
2017-08-17 22:00:37 +05:30
|
|
|
actor.try(:has_access_to?, for_project)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def success?
|
|
|
|
actor.present? || type == :ci
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def failed?
|
|
|
|
!success?
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
def auth_user
|
|
|
|
actor.is_a?(User) ? actor : nil
|
|
|
|
end
|
|
|
|
alias_method :user, :auth_user
|
|
|
|
|
|
|
|
def deploy_token
|
|
|
|
actor.is_a?(DeployToken) ? actor : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def can?(action)
|
|
|
|
actor&.can?(action)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_perform_action_on_project?(action, given_project)
|
|
|
|
Ability.allowed?(actor, action, given_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authentication_abilities_include?(ability)
|
|
|
|
return false if authentication_abilities.blank?
|
|
|
|
|
|
|
|
authentication_abilities.include?(ability)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Gitlab::Auth::Result.prepend_mod_with('Gitlab::Auth::Result')
|