diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/auth/result.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/auth/result.rb')
-rw-r--r-- | lib/gitlab/auth/result.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/gitlab/auth/result.rb b/lib/gitlab/auth/result.rb index da874524826..69525a281e9 100644 --- a/lib/gitlab/auth/result.rb +++ b/lib/gitlab/auth/result.rb @@ -2,7 +2,18 @@ module Gitlab module Auth - Result = Struct.new(:actor, :project, :type, :authentication_abilities) do + 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 + def ci?(for_project) type == :ci && project && @@ -21,6 +32,29 @@ module Gitlab def failed? !success? end + + 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 end end end |