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.

40 lines
1 KiB
Ruby
Raw Normal View History

2022-03-02 08:16:31 +05:30
# frozen_string_literal: true
module WorkItems
class CreateService
2022-04-04 11:22:00 +05:30
include ::Services::ReturnServiceResponses
2022-03-02 08:16:31 +05:30
def initialize(project:, current_user: nil, params: {}, spam_params:)
@create_service = ::Issues::CreateService.new(
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-04-04 11:22:00 +05:30
@current_user = current_user
@project = project
2022-03-02 08:16:31 +05:30
end
def execute
2022-04-04 11:22:00 +05:30
unless @current_user.can?(:create_work_item, @project)
return error(_('Operation not allowed'), :forbidden)
end
work_item = @create_service.execute
if work_item.valid?
success(payload(work_item))
else
error(work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(work_item))
end
end
private
def payload(work_item)
{ work_item: work_item }
2022-03-02 08:16:31 +05:30
end
end
end