diff options
Diffstat (limited to 'app/services/work_items/create_service.rb')
-rw-r--r-- | app/services/work_items/create_service.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/services/work_items/create_service.rb b/app/services/work_items/create_service.rb index 705735fe403..c2ceb701a2f 100644 --- a/app/services/work_items/create_service.rb +++ b/app/services/work_items/create_service.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true module WorkItems - class CreateService + class CreateService < Issues::CreateService include ::Services::ReturnServiceResponses + include WidgetableService - def initialize(project:, current_user: nil, params: {}, spam_params:) - @create_service = ::Issues::CreateService.new( + def initialize(project:, current_user: nil, params: {}, spam_params:, widget_params: {}) + super( 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) ) - @current_user = current_user - @project = project + @widget_params = widget_params end def execute @@ -21,13 +21,24 @@ module WorkItems return error(_('Operation not allowed'), :forbidden) end - work_item = @create_service.execute + work_item = super if work_item.valid? success(payload(work_item)) else error(work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(work_item)) end + 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 end private |