diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-02 18:10:01 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-02 18:10:01 +0000 |
commit | e84a2fdfc862ac63fe4be9df2f940c22a0c9aba3 (patch) | |
tree | 8a64589231ede24f385d2819b3440fca001e482d /app/graphql | |
parent | 1c2ff01b694fd06be15bc20279eef71ee5adf402 (diff) | |
download | gitlab-ce-e84a2fdfc862ac63fe4be9df2f940c22a0c9aba3.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/mutations/ci/runner/delete.rb | 44 | ||||
-rw-r--r-- | app/graphql/types/mutation_type.rb | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/app/graphql/mutations/ci/runner/delete.rb b/app/graphql/mutations/ci/runner/delete.rb new file mode 100644 index 00000000000..8d9a5f15505 --- /dev/null +++ b/app/graphql/mutations/ci/runner/delete.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Runner + class Delete < BaseMutation + graphql_name 'RunnerDelete' + + authorize :delete_runner + + RunnerID = ::Types::GlobalIDType[::Ci::Runner] + + argument :id, RunnerID, + required: true, + description: 'ID of the runner to delete.' + + def resolve(id:, **runner_attrs) + runner = authorized_find!(id) + + error = authenticate_delete_runner!(runner) + return { errors: [error] } if error + + runner.destroy! + + { errors: runner.errors.full_messages } + end + + def authenticate_delete_runner!(runner) + return if current_user.can_admin_all_resources? + + "Runner #{runner.to_global_id} associated with more than one project" if runner.projects.count > 1 + end + + def find_object(id) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = RunnerID.coerce_isolated_input(id) + + GitlabSchema.find_by_gid(id) + end + end + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index df0e5484ae7..561cbf24da3 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -100,6 +100,7 @@ module Types mount_mutation Mutations::Ci::Job::Play mount_mutation Mutations::Ci::Job::Retry mount_mutation Mutations::Ci::Runner::Update, feature_flag: :runner_graphql_query + mount_mutation Mutations::Ci::Runner::Delete, feature_flag: :runner_graphql_query mount_mutation Mutations::Namespace::PackageSettings::Update mount_mutation Mutations::UserCallouts::Create end |