summaryrefslogtreecommitdiff
path: root/lib/api/project_debian_distributions.rb
blob: 58edf51f4f72944d0d201d09c97ac7859108cc69 (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
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module API
  class ProjectDebianDistributions < ::API::Base
    params do
      requires :id, type: String, desc: 'The ID of a project'
    end

    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      rescue_from ArgumentError do |e|
        render_api_error!(e.message, 400)
      end

      rescue_from ActiveRecord::RecordInvalid do |e|
        render_api_error!(e.message, 400)
      end

      after_validation do
        require_packages_enabled!

        not_found! unless ::Feature.enabled?(:debian_packages, user_project)

        authorize_read_package!
      end

      namespace ':id' do
        helpers do
          def project_or_group
            user_project
          end
        end

        include ::API::Concerns::Packages::DebianDistributionEndpoints
      end
    end
  end
end