2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
module API
|
|
|
|
module BoardsResponses
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
helpers do
|
|
|
|
def board
|
|
|
|
board_parent.boards.find(params[:board_id])
|
|
|
|
end
|
|
|
|
|
2020-10-31 02:09:06 -04:00
|
|
|
def create_board
|
|
|
|
forbidden! unless board_parent.multiple_issue_boards_available?
|
|
|
|
|
|
|
|
response =
|
|
|
|
::Boards::CreateService.new(board_parent, current_user, { name: params[:name] }).execute
|
|
|
|
|
|
|
|
present response.payload, with: Entities::Board
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_board
|
|
|
|
service = ::Boards::UpdateService.new(board_parent, current_user, declared_params(include_missing: false))
|
|
|
|
service.execute(board)
|
|
|
|
|
|
|
|
if board.valid?
|
|
|
|
present board, with: Entities::Board
|
|
|
|
else
|
|
|
|
bad_request!("Failed to save board #{board.errors.messages}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_board
|
|
|
|
forbidden! unless board_parent.multiple_issue_boards_available?
|
|
|
|
|
|
|
|
destroy_conditionally!(board) do |board|
|
|
|
|
service = ::Boards::DestroyService.new(board_parent, current_user)
|
|
|
|
service.execute(board)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
def board_lists
|
2019-06-13 18:20:03 -04:00
|
|
|
board.destroyable_lists
|
2017-12-06 14:07:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_list
|
|
|
|
create_list_service =
|
2020-12-14 22:10:12 -05:00
|
|
|
::Boards::Lists::CreateService.new(board_parent, current_user, declared_params.compact.with_indifferent_access)
|
2017-12-06 14:07:47 -05:00
|
|
|
|
2020-12-09 10:10:12 -05:00
|
|
|
response = create_list_service.execute(board)
|
2017-12-06 14:07:47 -05:00
|
|
|
|
2020-12-09 10:10:12 -05:00
|
|
|
if response.success?
|
|
|
|
present response.payload[:list], with: Entities::List
|
2017-12-06 14:07:47 -05:00
|
|
|
else
|
2020-12-09 10:10:12 -05:00
|
|
|
render_api_error!({ error: response.errors.first }, 400)
|
2017-12-06 14:07:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_list(list)
|
|
|
|
move_list_service =
|
|
|
|
::Boards::Lists::MoveService.new(board_parent, current_user, { position: params[:position].to_i })
|
|
|
|
|
|
|
|
if move_list_service.execute(list)
|
|
|
|
present list, with: Entities::List
|
|
|
|
else
|
|
|
|
render_api_error!({ error: "List could not be moved!" }, 400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_list(list)
|
|
|
|
destroy_conditionally!(list) do |list|
|
|
|
|
service = ::Boards::Lists::DestroyService.new(board_parent, current_user)
|
2020-09-24 08:09:37 -04:00
|
|
|
if service.execute(list).error?
|
2017-12-06 14:07:47 -05:00
|
|
|
render_api_error!({ error: 'List could not be deleted!' }, 400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-07 13:29:06 -04:00
|
|
|
|
|
|
|
params :list_creation_params do
|
|
|
|
requires :label_id, type: Integer, desc: 'The ID of an existing label'
|
|
|
|
end
|
2020-10-31 02:09:06 -04:00
|
|
|
|
2021-01-12 07:10:49 -05:00
|
|
|
params :update_params_ce do
|
|
|
|
optional :name, type: String, desc: 'The board name'
|
|
|
|
optional :hide_backlog_list, type: Grape::API::Boolean, desc: 'Hide the Open list'
|
|
|
|
optional :hide_closed_list, type: Grape::API::Boolean, desc: 'Hide the Closed list'
|
|
|
|
end
|
|
|
|
|
|
|
|
params :update_params_ee do
|
2020-10-31 02:09:06 -04:00
|
|
|
# Configurable issue boards are not available in CE/EE Core.
|
|
|
|
# https://docs.gitlab.com/ee/user/project/issue_board.html#configurable-issue-boards
|
2021-01-12 07:10:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
params :update_params do
|
|
|
|
use :update_params_ce
|
|
|
|
use :update_params_ee
|
2020-10-31 02:09:06 -04:00
|
|
|
end
|
2017-12-06 14:07:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|