2018-10-11 16:12:21 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
2016-09-19 07:42:10 -04:00
|
|
|
module Auth
|
2021-08-17 14:10:35 -04:00
|
|
|
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
|
2021-08-04 14:09:57 -04:00
|
|
|
|
2016-09-20 04:24:47 -04:00
|
|
|
def ci?(for_project)
|
|
|
|
type == :ci &&
|
|
|
|
project &&
|
|
|
|
project == for_project
|
2016-09-19 07:42:10 -04:00
|
|
|
end
|
|
|
|
|
2016-09-20 04:24:47 -04:00
|
|
|
def lfs_deploy_token?(for_project)
|
|
|
|
type == :lfs_deploy_token &&
|
2016-11-16 07:31:08 -05:00
|
|
|
actor.try(:has_access_to?, for_project)
|
2016-09-19 10:34:32 -04:00
|
|
|
end
|
|
|
|
|
2016-09-19 07:42:10 -04:00
|
|
|
def success?
|
|
|
|
actor.present? || type == :ci
|
|
|
|
end
|
2017-05-31 09:55:12 -04:00
|
|
|
|
|
|
|
def failed?
|
|
|
|
!success?
|
|
|
|
end
|
2021-07-27 08:10:54 -04:00
|
|
|
|
|
|
|
def auth_user
|
|
|
|
actor.is_a?(User) ? actor : nil
|
|
|
|
end
|
2021-08-17 14:10:35 -04:00
|
|
|
alias_method :user, :auth_user
|
2021-07-27 08:10:54 -04:00
|
|
|
|
|
|
|
def deploy_token
|
|
|
|
actor.is_a?(DeployToken) ? actor : nil
|
|
|
|
end
|
2021-08-04 14:09:57 -04:00
|
|
|
|
|
|
|
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-19 07:42:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 08:09:44 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Gitlab::Auth::Result.prepend_mod_with('Gitlab::Auth::Result')
|