Class: Gitlab::Auth::Result
- Inherits:
-
Object
- Object
- Gitlab::Auth::Result
- Defined in:
- lib/gitlab/auth/result.rb
Constant Summary collapse
- EMPTY =
self.new(nil, nil, nil, nil).freeze
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#authentication_abilities ⇒ Object
readonly
Returns the value of attribute authentication_abilities.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #auth_user ⇒ Object (also: #user)
- #authentication_abilities_include?(ability) ⇒ Boolean
- #can?(action) ⇒ Boolean
- #can_perform_action_on_project?(action, given_project) ⇒ Boolean
- #ci?(for_project) ⇒ Boolean
- #deploy_token ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(actor, project, type, authentication_abilities) ⇒ Result
constructor
A new instance of Result.
- #lfs_deploy_token?(for_project) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(actor, project, type, authentication_abilities) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 |
# File 'lib/gitlab/auth/result.rb', line 8 def initialize(actor, project, type, authentication_abilities) @actor = actor @project = project @type = type @authentication_abilities = authentication_abilities end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
6 7 8 |
# File 'lib/gitlab/auth/result.rb', line 6 def actor @actor end |
#authentication_abilities ⇒ Object (readonly)
Returns the value of attribute authentication_abilities.
6 7 8 |
# File 'lib/gitlab/auth/result.rb', line 6 def authentication_abilities @authentication_abilities end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/gitlab/auth/result.rb', line 6 def project @project end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/gitlab/auth/result.rb', line 6 def type @type end |
Instance Method Details
#auth_user ⇒ Object Also known as: user
36 37 38 |
# File 'lib/gitlab/auth/result.rb', line 36 def auth_user actor.is_a?(User) ? actor : nil end |
#authentication_abilities_include?(ability) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/gitlab/auth/result.rb', line 53 def authentication_abilities_include?(ability) return false if authentication_abilities.blank? authentication_abilities.include?(ability) end |
#can?(action) ⇒ Boolean
45 46 47 |
# File 'lib/gitlab/auth/result.rb', line 45 def can?(action) actor&.can?(action) end |
#can_perform_action_on_project?(action, given_project) ⇒ Boolean
49 50 51 |
# File 'lib/gitlab/auth/result.rb', line 49 def can_perform_action_on_project?(action, given_project) Ability.allowed?(actor, action, given_project) end |
#ci?(for_project) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/gitlab/auth/result.rb', line 17 def ci?(for_project) type == :ci && project && project == for_project end |
#deploy_token ⇒ Object
41 42 43 |
# File 'lib/gitlab/auth/result.rb', line 41 def deploy_token actor.is_a?(DeployToken) ? actor : nil end |
#failed? ⇒ Boolean
32 33 34 |
# File 'lib/gitlab/auth/result.rb', line 32 def failed? !success? end |
#lfs_deploy_token?(for_project) ⇒ Boolean
23 24 25 26 |
# File 'lib/gitlab/auth/result.rb', line 23 def lfs_deploy_token?(for_project) type == :lfs_deploy_token && actor.try(:has_access_to?, for_project) end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/gitlab/auth/result.rb', line 28 def success? actor.present? || type == :ci end |