group_boards.rb 3.4 KB
Newer Older
1 2
# frozen_string_literal: true

F
Felipe Artur 已提交
3 4 5 6 7
module API
  class GroupBoards < Grape::API
    include BoardsResponses
    include PaginationParams

8 9
    prepend_if_ee('EE::API::BoardsResponses') # rubocop: disable Cop/InjectEnterpriseEditionModule

F
Felipe Artur 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23
    before do
      authenticate!
    end

    helpers do
      def board_parent
        user_group
      end
    end

    params do
      requires :id, type: String, desc: 'The ID of a group'
    end

24
    resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
F
Felipe Artur 已提交
25 26 27 28 29 30
      segment ':id/boards' do
        desc 'Find a group board' do
          detail 'This feature was introduced in 10.6'
          success ::API::Entities::Board
        end
        get '/:board_id' do
31
          authorize!(:read_board, user_group)
F
Felipe Artur 已提交
32 33 34 35 36 37 38 39 40 41 42
          present board, with: ::API::Entities::Board
        end

        desc 'Get all group boards' do
          detail 'This feature was introduced in 10.6'
          success Entities::Board
        end
        params do
          use :pagination
        end
        get '/' do
43
          authorize!(:read_board, user_group)
44
          present paginate(board_parent.boards.with_associations), with: Entities::Board
F
Felipe Artur 已提交
45 46 47 48 49 50 51 52
        end
      end

      params do
        requires :board_id, type: Integer, desc: 'The ID of a board'
      end
      segment ':id/boards/:board_id' do
        desc 'Get the lists of a group board' do
F
Felipe Artur 已提交
53
          detail 'Does not include backlog and closed lists. This feature was introduced in 10.6'
F
Felipe Artur 已提交
54 55 56 57 58 59
          success Entities::List
        end
        params do
          use :pagination
        end
        get '/lists' do
60
          authorize!(:read_board, user_group)
F
Felipe Artur 已提交
61 62 63 64 65 66 67 68 69 70 71
          present paginate(board_lists), with: Entities::List
        end

        desc 'Get a list of a group board' do
          detail 'This feature was introduced in 10.6'
          success Entities::List
        end
        params do
          requires :list_id, type: Integer, desc: 'The ID of a list'
        end
        get '/lists/:list_id' do
72
          authorize!(:read_board, user_group)
F
Felipe Artur 已提交
73 74 75 76 77 78 79 80
          present board_lists.find(params[:list_id]), with: Entities::List
        end

        desc 'Create a new board list' do
          detail 'This feature was introduced in 10.6'
          success Entities::List
        end
        params do
81
          use :list_creation_params
F
Felipe Artur 已提交
82 83
        end
        post '/lists' do
84
          authorize_list_type_resource!
F
Felipe Artur 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

          authorize!(:admin_list, user_group)

          create_list
        end

        desc 'Moves a board list to a new position' do
          detail 'This feature was introduced in 10.6'
          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
        put '/lists/:list_id' do
          list = board_lists.find(params[:list_id])

          authorize!(:admin_list, user_group)

          move_list(list)
        end

        desc 'Delete a board list' do
          detail 'This feature was introduced in 10.6'
          success Entities::List
        end
        params do
          requires :list_id, type: Integer, desc: 'The ID of a board list'
        end
        delete "/lists/:list_id" do
          authorize!(:admin_list, user_group)
          list = board_lists.find(params[:list_id])

          destroy_list(list)
        end
      end
    end
  end
end