Class: Gitlab::Graphql::Authorize::ObjectAuthorization

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/graphql/authorize/object_authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abilities, scopes = %i[api read_api]) ⇒ ObjectAuthorization

Returns a new instance of ObjectAuthorization.


9
10
11
12
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 9

def initialize(abilities, scopes = %i[api read_api])
  @abilities = Array.wrap(abilities).flatten
  @permitted_scopes = Array.wrap(scopes)
end

Instance Attribute Details

#abilitiesObject (readonly)

Returns the value of attribute abilities.


7
8
9
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 7

def abilities
  @abilities
end

#permitted_scopesObject (readonly)

Returns the value of attribute permitted_scopes.


7
8
9
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 7

def permitted_scopes
  @permitted_scopes
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 18

def any?
  abilities.present?
end

#none?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 14

def none?
  abilities.empty?
end

#ok?(object, current_user, scope_validator: nil) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/gitlab/graphql/authorize/object_authorization.rb', line 22

def ok?(object, current_user, scope_validator: nil)
  scopes_ok?(scope_validator) && abilities_ok?(object, current_user)
end