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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
991 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?
2021-03-11 19:13:27 +05:30
parent_board_collection.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!
2021-03-11 19:13:27 +05:30
board = parent_board_collection.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
2021-03-11 19:13:27 +05:30
def parent_board_collection
parent.boards
end
2016-09-13 17:45:13 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Boards::CreateService.prepend_mod_with('Boards::CreateService')