blob: 54dab581686642698959b332f7bdc81129b2406d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# frozen_string_literal: true
module Boards
class CreateService < Boards::BaseService
def execute
unless can_create_board?
return ServiceResponse.error(message: "You don't have the permission to create a board for this resource.")
end
create_board!
end
private
def can_create_board?
parent_board_collection.empty? || parent.multiple_issue_boards_available?
end
def create_board!
board = parent_board_collection.create(params)
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)
end
ServiceResponse.success(payload: board)
end
def parent_board_collection
parent.boards
end
end
end
Boards::CreateService.prepend_if_ee('EE::Boards::CreateService')
|