debian-mirror-gitlab/app/graphql/mutations/work_items/update.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.9 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
module Mutations
module WorkItems
class Update < BaseMutation
graphql_name 'WorkItemUpdate'
2023-01-13 00:05:48 +05:30
description "Updates a work item by Global ID."
2022-04-04 11:22:00 +05:30
include Mutations::SpamProtection
2022-07-23 23:45:48 +05:30
include Mutations::WorkItems::UpdateArguments
2022-08-13 15:12:31 +05:30
include Mutations::WorkItems::Widgetable
2022-04-04 11:22:00 +05:30
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-08-13 15:12:31 +05:30
widget_params = extract_widget_params!(work_item.work_item_type, attributes)
2022-04-04 11:22:00 +05:30
2023-04-23 21:23:45 +05:30
interpret_quick_actions!(work_item, current_user, widget_params, attributes)
2022-08-13 15:12:31 +05:30
update_result = ::WorkItems::UpdateService.new(
2023-04-23 21:23:45 +05:30
container: work_item.project,
2022-04-04 11:22:00 +05:30
current_user: current_user,
params: attributes,
2022-08-13 15:12:31 +05:30
widget_params: widget_params,
2022-04-04 11:22:00 +05:30
spam_params: spam_params
).execute(work_item)
check_spam_action_response!(work_item)
{
2022-08-13 15:12:31 +05:30
work_item: (update_result[:work_item] if update_result[:status] == :success),
errors: Array.wrap(update_result[:message])
2022-04-04 11:22:00 +05:30
}
end
private
def find_object(id:)
GitlabSchema.find_by_gid(id)
end
2023-04-23 21:23:45 +05:30
def interpret_quick_actions!(work_item, current_user, widget_params, attributes = {})
return unless work_item.work_item_type.widgets.include?(::WorkItems::Widgets::Description)
description_param = widget_params[::WorkItems::Widgets::Description.api_symbol]
return unless description_param
original_description = description_param.fetch(:description, work_item.description)
description, command_params = QuickActions::InterpretService
.new(work_item.project, current_user, {})
.execute(original_description, work_item)
description_param[:description] = description if description && description != original_description
# Widgets have a set of quick action params that they must process.
# Map them to widget_params so they can be picked up by widget services.
work_item.work_item_type.widgets
.filter { |widget| widget.respond_to?(:quick_action_params) }
.each do |widget|
widget.quick_action_params
.filter { |param_name| command_params.key?(param_name) }
.each do |param_name|
widget_params[widget.api_symbol] ||= {}
widget_params[widget.api_symbol][param_name] = command_params.delete(param_name)
end
end
# The command_params not processed by widgets (e.g. title) should be placed in 'attributes'.
attributes.merge!(command_params || {})
end
2022-04-04 11:22:00 +05:30
end
end
end
2022-08-27 11:52:29 +05:30
Mutations::WorkItems::Update.prepend_mod