Class: Types::PermissionTypes::BasePermissionType

Inherits:
BaseObject
  • Object
show all
Extended by:
Gitlab::Allowable
Defined in:
app/graphql/types/permission_types/base_permission_type.rb

Direct Known Subclasses

Ci::Pipeline, Group, Issue, MergeRequest, Note, Project, Snippet, User

Constant Summary collapse

RESOLVING_KEYWORDS =
[:resolver, :method, :hash_key, :function].to_set.freeze

Class Method Summary collapse

Methods included from Gitlab::Allowable

can?

Methods inherited from BaseObject

#current_user, #id

Class Method Details

.abilities(*abilities) ⇒ Object


10
11
12
# File 'app/graphql/types/permission_types/base_permission_type.rb', line 10

def self.abilities(*abilities)
  abilities.each { |ability| ability_field(ability) }
end

.ability_field(ability, **kword_args) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'app/graphql/types/permission_types/base_permission_type.rb', line 14

def self.ability_field(ability, **kword_args)
  unless resolving_keywords?(kword_args)
    kword_args[:resolve] ||= -> (object, args, context) do
      can?(context[:current_user], ability, object, args.to_h)
    end
  end

  permission_field(ability, **kword_args)
end

.permission_field(name, **kword_args) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'app/graphql/types/permission_types/base_permission_type.rb', line 24

def self.permission_field(name, **kword_args)
  kword_args = kword_args.reverse_merge(
    name: name,
    type: GraphQL::BOOLEAN_TYPE,
    description: "Indicates the user can perform `#{name}` on this resource",
    null: false)

  field(**kword_args) # rubocop:disable Graphql/Descriptions
end