2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-02 23:12:59 -04:00
|
|
|
module API
|
2020-04-27 23:09:53 -04:00
|
|
|
class Boards < Grape::API
|
2017-12-06 14:07:47 -05:00
|
|
|
include BoardsResponses
|
2017-01-16 23:45:07 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2019-09-13 09:26:31 -04:00
|
|
|
prepend_if_ee('EE::API::BoardsResponses') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2016-10-02 23:12:59 -04:00
|
|
|
before { authenticate! }
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
helpers do
|
|
|
|
def board_parent
|
|
|
|
user_project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2018-11-08 07:18:17 -05:00
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2017-12-06 14:07:47 -05:00
|
|
|
segment ':id/boards' do
|
|
|
|
desc 'Get all project boards' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::Board
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get '/' do
|
|
|
|
authorize!(:read_board, user_project)
|
2019-06-13 18:20:03 -04:00
|
|
|
present paginate(board_parent.boards.with_associations), with: Entities::Board
|
2017-12-06 14:07:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Find a project board' do
|
|
|
|
detail 'This feature was introduced in 10.4'
|
|
|
|
success Entities::Board
|
|
|
|
end
|
|
|
|
get '/:board_id' do
|
2018-07-04 05:52:58 -04:00
|
|
|
authorize!(:read_board, user_project)
|
2017-12-06 14:07:47 -05:00
|
|
|
present board, with: Entities::Board
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
params do
|
|
|
|
requires :board_id, type: Integer, desc: 'The ID of a board'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
segment ':id/boards/:board_id' do
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Get the lists of a project board' do
|
2017-01-27 00:26:48 -05:00
|
|
|
detail 'Does not include `done` list. This feature was introduced in 8.13'
|
2016-10-14 03:38:20 -04:00
|
|
|
success Entities::List
|
|
|
|
end
|
2017-01-16 23:45:07 -05:00
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
get '/lists' do
|
|
|
|
authorize!(:read_board, user_project)
|
2017-01-16 23:45:07 -05:00
|
|
|
present paginate(board_lists), with: Entities::List
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Get a list of a project board' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
get '/lists/:list_id' do
|
|
|
|
authorize!(:read_board, user_project)
|
|
|
|
present board_lists.find(params[:list_id]), with: Entities::List
|
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Create a new board list' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
2018-08-07 13:29:06 -04:00
|
|
|
use :list_creation_params
|
2016-10-14 03:38:20 -04:00
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
post '/lists' do
|
2018-08-07 13:29:06 -04:00
|
|
|
authorize_list_type_resource!
|
2016-10-02 23:12:59 -04:00
|
|
|
|
|
|
|
authorize!(:admin_list, user_project)
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
create_list
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Moves a board list to a new position' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a list'
|
|
|
|
requires :position, type: Integer, desc: 'The position of the list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
put '/lists/:list_id' do
|
2017-12-06 14:07:47 -05:00
|
|
|
list = board_lists.find(params[:list_id])
|
2016-10-02 23:12:59 -04:00
|
|
|
|
|
|
|
authorize!(:admin_list, user_project)
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
move_list(list)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 03:38:20 -04:00
|
|
|
desc 'Delete a board list' do
|
|
|
|
detail 'This feature was introduced in 8.13'
|
|
|
|
success Entities::List
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :list_id, type: Integer, desc: 'The ID of a board list'
|
|
|
|
end
|
2016-10-02 23:12:59 -04:00
|
|
|
delete "/lists/:list_id" do
|
|
|
|
authorize!(:admin_list, user_project)
|
2016-10-06 16:36:46 -04:00
|
|
|
list = board_lists.find(params[:list_id])
|
|
|
|
|
2017-12-06 14:07:47 -05:00
|
|
|
destroy_list(list)
|
2016-10-02 23:12:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|