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