summaryrefslogtreecommitdiff
path: root/app/services/boards/create_service.rb
blob: 1a5dc790c415cee55564d5d741f8f0ee7e1a4bf4 (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
# frozen_string_literal: true

module Boards
  class CreateService < Boards::BaseService
    def execute
      create_board! if can_create_board?
    end

    private

    def can_create_board?
      parent.boards.empty? || parent.multiple_issue_boards_available?
    end

    def create_board!
      board = parent.boards.create(params)

      if board.persisted?
        board.lists.create(list_type: :backlog)
        board.lists.create(list_type: :closed)
      end

      board
    end
  end
end

Boards::CreateService.prepend_if_ee('EE::Boards::CreateService')