2017-02-06 13:38:17 -05:00
|
|
|
module API
|
|
|
|
module V3
|
|
|
|
class Labels < Grape::API
|
|
|
|
before { authenticate! }
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
2017-03-15 14:09:24 -04:00
|
|
|
resource :projects, requirements: { id: %r{[^/]+} } do
|
2017-02-06 13:38:17 -05:00
|
|
|
desc 'Get all labels of the project' do
|
|
|
|
success ::API::Entities::Label
|
|
|
|
end
|
|
|
|
get ':id/labels' do
|
2017-12-06 14:07:47 -05:00
|
|
|
present available_labels_for(user_project), with: ::API::Entities::Label, current_user: current_user, project: user_project
|
2017-02-06 13:38:17 -05:00
|
|
|
end
|
2017-02-20 14:32:44 -05:00
|
|
|
|
|
|
|
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
|
2017-02-06 13:38:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|