2022-03-02 08:16:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module WorkItems
|
2022-08-13 15:12:31 +05:30
|
|
|
class CreateService < Issues::CreateService
|
2023-06-20 00:43:36 +05:30
|
|
|
extend ::Gitlab::Utils::Override
|
2022-08-13 15:12:31 +05:30
|
|
|
include WidgetableService
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def initialize(container:, spam_params:, current_user: nil, params: {}, widget_params: {})
|
2022-08-13 15:12:31 +05:30
|
|
|
super(
|
2023-04-23 21:23:45 +05:30
|
|
|
container: container,
|
2022-03-02 08:16:31 +05:30
|
|
|
current_user: current_user,
|
|
|
|
params: params,
|
|
|
|
spam_params: spam_params,
|
2023-04-23 21:23:45 +05:30
|
|
|
build_service: ::WorkItems::BuildService.new(container: container, current_user: current_user, params: params)
|
2022-03-02 08:16:31 +05:30
|
|
|
)
|
2022-08-13 15:12:31 +05:30
|
|
|
@widget_params = widget_params
|
2022-03-02 08:16:31 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2022-11-25 23:54:43 +05:30
|
|
|
result = super
|
|
|
|
return result if result.error?
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
work_item = result[:issue]
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
if work_item.valid?
|
|
|
|
success(payload(work_item))
|
|
|
|
else
|
|
|
|
error(work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(work_item))
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
rescue ::WorkItems::Widgets::BaseService::WidgetError => e
|
|
|
|
error(e.message, :unprocessable_entity)
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
def before_create(work_item)
|
|
|
|
execute_widgets(work_item: work_item, callback: :before_create_callback,
|
|
|
|
widget_params: @widget_params)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def transaction_create(work_item)
|
|
|
|
super.tap do |save_result|
|
|
|
|
if save_result
|
|
|
|
execute_widgets(work_item: work_item, callback: :after_create_in_transaction,
|
|
|
|
widget_params: @widget_params)
|
|
|
|
end
|
|
|
|
end
|
2022-04-04 11:22:00 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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 if work_item.work_item_type != WorkItems::Type.default_by_type(:issue)
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def authorization_action
|
|
|
|
:create_work_item
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
def payload(work_item)
|
|
|
|
{ work_item: work_item }
|
2022-03-02 08:16:31 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|