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.
-
#authentication_context ⇒ Object
readonly
Returns the value of attribute authentication_context.
-
#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, authentication_context = {}) ⇒ Result
constructor
A new instance of Result.
- #lfs_deploy_token?(for_project) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(actor, project, type, authentication_abilities, authentication_context = {}) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 14 |
# File 'lib/gitlab/auth/result.rb', line 8 def initialize(actor, project, type, authentication_abilities, authentication_context = {}) @actor = actor @project = project @type = type @authentication_abilities = authentication_abilities @authentication_context = authentication_context 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 |
#authentication_context ⇒ Object (readonly)
Returns the value of attribute authentication_context.
6 7 8 |
# File 'lib/gitlab/auth/result.rb', line 6 def authentication_context @authentication_context 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
37 38 39 |
# File 'lib/gitlab/auth/result.rb', line 37 def auth_user actor.is_a?(User) ? actor : nil end |
#authentication_abilities_include?(ability) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/gitlab/auth/result.rb', line 54 def authentication_abilities_include?(ability) return false if authentication_abilities.blank? authentication_abilities.include?(ability) end |
#can?(action) ⇒ Boolean
46 47 48 |
# File 'lib/gitlab/auth/result.rb', line 46 def can?(action) actor&.can?(action) end |
#can_perform_action_on_project?(action, given_project) ⇒ Boolean
50 51 52 |
# File 'lib/gitlab/auth/result.rb', line 50 def can_perform_action_on_project?(action, given_project) Ability.allowed?(actor, action, given_project) end |
#ci?(for_project) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/gitlab/auth/result.rb', line 18 def ci?(for_project) type == :ci && project && project == for_project end |
#deploy_token ⇒ Object
42 43 44 |
# File 'lib/gitlab/auth/result.rb', line 42 def deploy_token actor.is_a?(DeployToken) ? actor : nil end |
#failed? ⇒ Boolean
33 34 35 |
# File 'lib/gitlab/auth/result.rb', line 33 def failed? !success? end |
#lfs_deploy_token?(for_project) ⇒ Boolean
24 25 26 27 |
# File 'lib/gitlab/auth/result.rb', line 24 def lfs_deploy_token?(for_project) type == :lfs_deploy_token && actor.try(:has_access_to?, for_project) end |
#success? ⇒ Boolean
29 30 31 |
# File 'lib/gitlab/auth/result.rb', line 29 def success? actor.present? || type == :ci end |