summaryrefslogtreecommitdiff
path: root/lib/api/v3/variables.rb
blob: 83972b1e7ce9d1fe631828fb9e16373b2a7ec3a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module API
  module V3
    class Variables < Grape::API
      include PaginationParams

      before { authenticate! }
      before { authorize! :admin_build, user_project }

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

      resource :projects, requirements: { id: %r{[^/]+} } do
        desc 'Delete an existing variable from a project' do
          success ::API::Entities::Variable
        end
        params do
          requires :key, type: String, desc: 'The key of the variable'
        end
        delete ':id/variables/:key' do
          variable = user_project.variables.find_by(key: params[:key])
          not_found!('Variable') unless variable

          present variable.destroy, with: ::API::Entities::Variable
        end
      end
    end
  end
end