boards.rb 3.2 KB
Newer Older
1 2
module API
  class Boards < Grape::API
Felipe Artur's avatar
Felipe Artur committed
3
    include BoardsResponses
4 5
    include PaginationParams

6 7
    before { authenticate! }

Felipe Artur's avatar
Felipe Artur committed
8 9 10 11 12 13
    helpers do
      def board_parent
        user_project
      end
    end

Robert Schilling's avatar
Robert Schilling committed
14 15 16
    params do
      requires :id, type: String, desc: 'The ID of a project'
    end
17
    resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
Felipe Artur's avatar
Felipe Artur committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
      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)
          present paginate(board_parent.boards), with: Entities::Board
        end

        desc 'Find a project board' do
          detail 'This feature was introduced in 10.4'
          success Entities::Board
        end
        get '/:board_id' do
Mark Chao's avatar
Mark Chao committed
36
          authorize!(:read_board, user_project)
Felipe Artur's avatar
Felipe Artur committed
37 38
          present board, with: Entities::Board
        end
39 40
      end

Robert Schilling's avatar
Robert Schilling committed
41 42 43
      params do
        requires :board_id, type: Integer, desc: 'The ID of a board'
      end
44
      segment ':id/boards/:board_id' do
Robert Schilling's avatar
Robert Schilling committed
45
        desc 'Get the lists of a project board' do
46
          detail 'Does not include `done` list. This feature was introduced in 8.13'
Robert Schilling's avatar
Robert Schilling committed
47 48
          success Entities::List
        end
49 50 51
        params do
          use :pagination
        end
52 53
        get '/lists' do
          authorize!(:read_board, user_project)
54
          present paginate(board_lists), with: Entities::List
55 56
        end

Robert Schilling's avatar
Robert Schilling committed
57 58 59 60 61 62 63
        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
64 65 66 67 68
        get '/lists/:list_id' do
          authorize!(:read_board, user_project)
          present board_lists.find(params[:list_id]), with: Entities::List
        end

Robert Schilling's avatar
Robert Schilling committed
69 70 71 72 73
        desc 'Create a new board list' do
          detail 'This feature was introduced in 8.13'
          success Entities::List
        end
        params do
74
          use :list_creation_params
Robert Schilling's avatar
Robert Schilling committed
75
        end
76
        post '/lists' do
77
          authorize_list_type_resource!
78 79 80

          authorize!(:admin_list, user_project)

Felipe Artur's avatar
Felipe Artur committed
81
          create_list
82 83
        end

Robert Schilling's avatar
Robert Schilling committed
84 85 86 87 88 89 90 91
        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
92
        put '/lists/:list_id' do
Felipe Artur's avatar
Felipe Artur committed
93
          list = board_lists.find(params[:list_id])
94 95 96

          authorize!(:admin_list, user_project)

Felipe Artur's avatar
Felipe Artur committed
97
          move_list(list)
98 99
        end

Robert Schilling's avatar
Robert Schilling committed
100 101 102 103 104 105 106
        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
107 108
        delete "/lists/:list_id" do
          authorize!(:admin_list, user_project)
109 110
          list = board_lists.find(params[:list_id])

Felipe Artur's avatar
Felipe Artur committed
111
          destroy_list(list)
112 113 114 115 116
        end
      end
    end
  end
end