2022-02-01 00:14:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module WorkItems
|
|
|
|
class Update < BaseMutation
|
2022-02-15 12:14:49 +00:00
|
|
|
graphql_name 'WorkItemUpdate'
|
2022-02-01 00:14:06 +00:00
|
|
|
description "Updates a work item by Global ID." \
|
2022-05-30 21:09:18 +00:00
|
|
|
" Available only when feature flag `work_items` is enabled."
|
2022-02-01 00:14:06 +00:00
|
|
|
|
2022-02-15 12:14:49 +00:00
|
|
|
include Mutations::SpamProtection
|
2022-05-25 12:08:10 +00:00
|
|
|
include Mutations::WorkItems::UpdateArguments
|
2022-02-01 00:14:06 +00:00
|
|
|
|
|
|
|
authorize :update_work_item
|
|
|
|
|
|
|
|
field :work_item, Types::WorkItemType,
|
|
|
|
null: true,
|
|
|
|
description: 'Updated work item.'
|
|
|
|
|
|
|
|
def resolve(id:, **attributes)
|
|
|
|
work_item = authorized_find!(id: id)
|
|
|
|
|
2022-03-23 15:08:38 +00:00
|
|
|
unless work_item.project.work_items_feature_flag_enabled?
|
2022-02-01 00:14:06 +00:00
|
|
|
return { errors: ['`work_items` feature flag disabled for this project'] }
|
|
|
|
end
|
|
|
|
|
|
|
|
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
|
|
|
|
|
|
|
|
::WorkItems::UpdateService.new(
|
|
|
|
project: work_item.project,
|
|
|
|
current_user: current_user,
|
|
|
|
params: attributes,
|
|
|
|
spam_params: spam_params
|
|
|
|
).execute(work_item)
|
|
|
|
|
|
|
|
check_spam_action_response!(work_item)
|
|
|
|
|
|
|
|
{
|
|
|
|
work_item: work_item.valid? ? work_item : nil,
|
|
|
|
errors: errors_on_object(work_item)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_object(id:)
|
|
|
|
GitlabSchema.find_by_gid(id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|