diff options
Diffstat (limited to 'app/graphql/mutations/work_items')
-rw-r--r-- | app/graphql/mutations/work_items/create.rb | 3 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/create_from_task.rb | 2 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/delete.rb | 2 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/delete_task.rb | 69 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/update.rb | 2 |
5 files changed, 69 insertions, 9 deletions
diff --git a/app/graphql/mutations/work_items/create.rb b/app/graphql/mutations/work_items/create.rb index c29dbb899b5..2e136d409ab 100644 --- a/app/graphql/mutations/work_items/create.rb +++ b/app/graphql/mutations/work_items/create.rb @@ -53,9 +53,6 @@ module Mutations private def global_id_compatibility_params(params) - # TODO: remove this line when the compatibility layer is removed - # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 - params[:work_item_type_id] = ::Types::GlobalIDType[::WorkItems::Type].coerce_isolated_input(params[:work_item_type_id]) if params[:work_item_type_id] params[:work_item_type_id] = params[:work_item_type_id]&.model_id params diff --git a/app/graphql/mutations/work_items/create_from_task.rb b/app/graphql/mutations/work_items/create_from_task.rb index 278c1bc65a9..4da709401a6 100644 --- a/app/graphql/mutations/work_items/create_from_task.rb +++ b/app/graphql/mutations/work_items/create_from_task.rb @@ -55,8 +55,6 @@ module Mutations private def find_object(id:) - # TODO: Remove coercion when working on https://gitlab.com/gitlab-org/gitlab/-/issues/257883 - id = ::Types::GlobalIDType[::WorkItem].coerce_isolated_input(id) GitlabSchema.find_by_gid(id) end end diff --git a/app/graphql/mutations/work_items/delete.rb b/app/graphql/mutations/work_items/delete.rb index 3d72ebbd95d..1830ab5443c 100644 --- a/app/graphql/mutations/work_items/delete.rb +++ b/app/graphql/mutations/work_items/delete.rb @@ -38,8 +38,6 @@ module Mutations private def find_object(id:) - # TODO: Remove coercion when working on https://gitlab.com/gitlab-org/gitlab/-/issues/257883 - id = ::Types::GlobalIDType[::WorkItem].coerce_isolated_input(id) GitlabSchema.find_by_gid(id) end end diff --git a/app/graphql/mutations/work_items/delete_task.rb b/app/graphql/mutations/work_items/delete_task.rb new file mode 100644 index 00000000000..87620a28fa1 --- /dev/null +++ b/app/graphql/mutations/work_items/delete_task.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Mutations + module WorkItems + class DeleteTask < BaseMutation + graphql_name 'WorkItemDeleteTask' + + description "Deletes a task in a work item's description." \ + ' Available only when feature flag `work_items` is enabled. This feature is experimental and' \ + ' is subject to change without notice.' + + authorize :update_work_item + + argument :id, ::Types::GlobalIDType[::WorkItem], + required: true, + description: 'Global ID of the work item.' + argument :lock_version, GraphQL::Types::Int, + required: true, + description: 'Current lock version of the work item containing the task in the description.' + argument :task_data, ::Types::WorkItems::DeletedTaskInputType, + required: true, + description: 'Arguments necessary to delete a task from a work item\'s description.', + prepare: ->(attributes, _ctx) { attributes.to_h } + + field :work_item, Types::WorkItemType, + null: true, + description: 'Updated work item.' + + def resolve(id:, lock_version:, task_data:) + work_item = authorized_find!(id: id) + task_data[:task] = authorized_find_task!(task_data[:id]) + + unless work_item.project.work_items_feature_flag_enabled? + return { errors: ['`work_items` feature flag disabled for this project'] } + end + + result = ::WorkItems::DeleteTaskService.new( + work_item: work_item, + current_user: current_user, + lock_version: lock_version, + task_params: task_data + ).execute + + response = { errors: result.errors } + response[:work_item] = work_item if result.success? + + response + end + + private + + def authorized_find_task!(task_id) + task = ::Gitlab::Graphql::Lazy.force(GitlabSchema.find_by_gid(task_id)) + + if current_user.can?(:delete_work_item, task) + task + else + # Fail early if user cannot delete task + raise_resource_not_available_error! + end + end + + # method used by `authorized_find!(id: id)` + def find_object(id:) + GitlabSchema.find_by_gid(id) + end + end + end +end diff --git a/app/graphql/mutations/work_items/update.rb b/app/graphql/mutations/work_items/update.rb index 091237d6fa0..20319301482 100644 --- a/app/graphql/mutations/work_items/update.rb +++ b/app/graphql/mutations/work_items/update.rb @@ -52,8 +52,6 @@ module Mutations private def find_object(id:) - # TODO: Remove coercion when working on https://gitlab.com/gitlab-org/gitlab/-/issues/257883 - id = ::Types::GlobalIDType[::WorkItem].coerce_isolated_input(id) GitlabSchema.find_by_gid(id) end end |