Class: Mutations::Users::PersonalAccessTokens::Create

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/mutations/users/personal_access_tokens/create.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorization_scopes, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Attribute Details

#granular_scopesObject (readonly)

Returns the value of attribute granular_scopes.



30
31
32
# File 'app/graphql/mutations/users/personal_access_tokens/create.rb', line 30

def granular_scopes
  @granular_scopes
end

Instance Method Details

#resolve(**args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/graphql/mutations/users/personal_access_tokens/create.rb', line 32

def resolve(**args)
  if Feature.disabled?(:granular_personal_access_tokens, current_user)
    raise_resource_not_available_error! '`granular_personal_access_tokens` feature flag is disabled.'
  end

  granular_scopes = build_granular_scopes(args.delete(:granular_scopes))
  response = ::Authn::PersonalAccessTokens::CreateGranularService.new(
    current_user: current_user,
    organization: Current.organization,
    params: args,
    granular_scopes: granular_scopes
  ).execute

  return { errors: Array(response.message) } if response.error?

  token = response[:personal_access_token]

  { token: token.token, errors: [] }
end