Class: Mutations::Ci::JobTokenScope::AddGroupOrProject

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsProject
Defined in:
app/graphql/mutations/ci/job_token_scope/add_group_or_project.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 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 Method Details

#resolve(project_path:, target_path:, default_permissions:, job_token_policies:) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/graphql/mutations/ci/job_token_scope/add_group_or_project.rb', line 46

def resolve(project_path:, target_path:, default_permissions:, job_token_policies:)
  project = authorized_find!(project_path)
  target = find_target_path(target_path)

  result = ::Ci::JobTokenScope::AddGroupOrProjectService
    .new(project, current_user)
    .execute(target, default_permissions: default_permissions, policies: job_token_policies)

  if result.success?
    {
      ci_job_token_scope: ::Ci::JobToken::Scope.new(project),
      ci_job_token_scope_allowlist_entry: result.payload.values[0],
      errors: []
    }
  else
    {
      ci_job_token_scope: nil,
      ci_job_token_scope_allowlist_entry: nil,
      errors: [result.message]
    }
  end
end