debian-mirror-gitlab/app/services/work_items/update_service.rb

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

81 lines
2.2 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
module WorkItems
class UpdateService < ::Issues::UpdateService
2023-06-20 00:43:36 +05:30
extend Gitlab::Utils::Override
2022-08-13 15:12:31 +05:30
include WidgetableService
2023-04-23 21:23:45 +05:30
def initialize(container:, current_user: nil, params: {}, spam_params: nil, widget_params: {})
2022-08-13 15:12:31 +05:30
params[:widget_params] = true if widget_params.present?
2023-04-23 21:23:45 +05:30
super(container: container, current_user: current_user, params: params, spam_params: spam_params)
2022-07-23 23:45:48 +05:30
@widget_params = widget_params
end
2022-08-13 15:12:31 +05:30
def execute(work_item)
updated_work_item = super
if updated_work_item.valid?
success(payload(work_item))
else
error(updated_work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(updated_work_item))
end
rescue ::WorkItems::Widgets::BaseService::WidgetError => e
error(e.message, :unprocessable_entity)
end
2022-04-04 11:22:00 +05:30
private
2023-06-20 00:43:36 +05:30
override :handle_quick_actions
def handle_quick_actions(work_item)
# Do not handle quick actions unless the work item is the default Issue.
# The available quick actions for a work item depend on its type and widgets.
return unless work_item.work_item_type.default_issue?
super
end
2022-11-25 23:54:43 +05:30
def prepare_update_params(work_item)
execute_widgets(
work_item: work_item,
callback: :prepare_update_params,
widget_params: @widget_params,
service_params: params
)
super
end
2022-08-27 11:52:29 +05:30
def before_update(work_item, skip_spam_check: false)
execute_widgets(work_item: work_item, callback: :before_update_callback, widget_params: @widget_params)
2022-08-13 15:12:31 +05:30
super
end
def transaction_update(work_item, opts = {})
execute_widgets(work_item: work_item, callback: :before_update_in_transaction, widget_params: @widget_params)
2022-07-23 23:45:48 +05:30
2022-04-04 11:22:00 +05:30
super
2022-07-23 23:45:48 +05:30
end
2022-11-25 23:54:43 +05:30
def after_update(work_item, old_associations)
2022-07-23 23:45:48 +05:30
super
GraphqlTriggers.issuable_title_updated(work_item) if work_item.previous_changes.key?(:title)
end
2022-04-04 11:22:00 +05:30
2022-08-13 15:12:31 +05:30
def payload(work_item)
{ work_item: work_item }
2022-04-04 11:22:00 +05:30
end
2022-11-25 23:54:43 +05:30
def handle_label_changes(issuable, old_labels)
return false unless super
Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter.track_work_item_labels_changed_action(
author: current_user
)
end
2022-04-04 11:22:00 +05:30
end
end