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

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

53 lines
1.3 KiB
Ruby
Raw Normal View History

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
include WidgetableService
2022-04-04 11:22:00 +05:30
2022-08-13 15:12:31 +05:30
def initialize(project:, current_user: nil, params: {}, spam_params:, widget_params: {})
super(
2022-03-02 08:16:31 +05:30
project: project,
current_user: current_user,
params: params,
spam_params: spam_params,
build_service: ::WorkItems::BuildService.new(project: project, current_user: current_user, params: params)
)
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
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
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