Class: Gitlab::Auth::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/auth/result.rb

Constant Summary collapse

EMPTY =
self.new(nil, nil, nil, nil).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actorObject (readonly)

Returns the value of attribute actor.


6
7
8
# File 'lib/gitlab/auth/result.rb', line 6

def actor
  @actor
end

#authentication_abilitiesObject (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

#projectObject (readonly)

Returns the value of attribute project.


6
7
8
# File 'lib/gitlab/auth/result.rb', line 6

def project
  @project
end

#typeObject (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_userObject 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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_tokenObject


41
42
43
# File 'lib/gitlab/auth/result.rb', line 41

def deploy_token
  actor.is_a?(DeployToken) ? actor : nil
end

#failed?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/gitlab/auth/result.rb', line 32

def failed?
  !success?
end

#lfs_deploy_token?(for_project) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)

28
29
30
# File 'lib/gitlab/auth/result.rb', line 28

def success?
  actor.present? || type == :ci
end