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-10-28 09:10:15 +00:00
|
|
|
description "Updates a work item by Global ID."
|
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-07-08 15:08:58 +00:00
|
|
|
include Mutations::WorkItems::Widgetable
|
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)
|
|
|
|
|
|
|
|
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
|
2022-07-19 09:08:45 +00:00
|
|
|
widget_params = extract_widget_params!(work_item.work_item_type, attributes)
|
2022-02-01 00:14:06 +00:00
|
|
|
|
2022-07-07 15:08:37 +00:00
|
|
|
update_result = ::WorkItems::UpdateService.new(
|
2022-02-01 00:14:06 +00:00
|
|
|
project: work_item.project,
|
|
|
|
current_user: current_user,
|
|
|
|
params: attributes,
|
2022-06-28 18:08:20 +00:00
|
|
|
widget_params: widget_params,
|
2022-02-01 00:14:06 +00:00
|
|
|
spam_params: spam_params
|
|
|
|
).execute(work_item)
|
|
|
|
|
|
|
|
check_spam_action_response!(work_item)
|
|
|
|
|
|
|
|
{
|
2022-07-07 15:08:37 +00:00
|
|
|
work_item: (update_result[:work_item] if update_result[:status] == :success),
|
|
|
|
errors: Array.wrap(update_result[:message])
|
2022-02-01 00:14:06 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_object(id:)
|
|
|
|
GitlabSchema.find_by_gid(id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-07-25 09:09:05 +00:00
|
|
|
|
|
|
|
Mutations::WorkItems::Update.prepend_mod
|