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

37 lines
911 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Boards
2018-03-17 18:26:18 +05:30
class CreateService < Boards::BaseService
2016-09-13 17:45:13 +05:30
def execute
2021-01-03 14:25:43 +05:30
unless can_create_board?
return ServiceResponse.error(message: "You don't have the permission to create a board for this resource.")
end
create_board!
2016-09-13 17:45:13 +05:30
end
private
2017-09-10 17:25:29 +05:30
def can_create_board?
2019-09-30 21:07:59 +05:30
parent.boards.empty? || parent.multiple_issue_boards_available?
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
def create_board!
2018-03-17 18:26:18 +05:30
board = parent.boards.create(params)
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
unless board.persisted?
return ServiceResponse.error(message: "There was an error when creating a board.", payload: board)
end
board.tap do |created_board|
created_board.lists.create(list_type: :backlog)
created_board.lists.create(list_type: :closed)
2017-09-10 17:25:29 +05:30
end
2016-11-03 12:29:30 +05:30
2021-01-03 14:25:43 +05:30
ServiceResponse.success(payload: board)
2016-09-13 17:45:13 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
Boards::CreateService.prepend_if_ee('EE::Boards::CreateService')