BigW Consortium Gitlab

labels.rb 1.02 KB
Newer Older
Robert Schilling committed
1 2 3 4 5 6 7 8
module API
  module V3
    class Labels < Grape::API
      before { authenticate! }

      params do
        requires :id, type: String, desc: 'The ID of a project'
      end
9
      resource :projects, requirements: { id: %r{[^/]+} } do
Robert Schilling committed
10 11 12 13 14 15
        desc 'Get all labels of the project' do
          success ::API::Entities::Label
        end
        get ':id/labels' do
          present available_labels, with: ::API::Entities::Label, current_user: current_user, project: user_project
        end
Robert Schilling committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

        desc 'Delete an existing label' do
          success ::API::Entities::Label
        end
        params do
          requires :name, type: String, desc: 'The name of the label to be deleted'
        end
        delete ':id/labels' do
          authorize! :admin_label, user_project

          label = user_project.labels.find_by(title: params[:name])
          not_found!('Label') unless label

          present label.destroy, with: ::API::Entities::Label, current_user: current_user, project: user_project
        end
Robert Schilling committed
31 32 33 34
      end
    end
  end
end