2020-07-17 02:09:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class PackageFiles < ::API::Base
|
2020-07-17 02:09:11 -04:00
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
before do
|
|
|
|
authorize_packages_access!(user_project)
|
|
|
|
end
|
|
|
|
|
2020-10-30 11:08:59 -04:00
|
|
|
feature_category :package_registry
|
2022-05-06 17:08:35 -04:00
|
|
|
urgency :low
|
2020-10-30 11:08:59 -04:00
|
|
|
|
2020-07-17 02:09:11 -04:00
|
|
|
helpers ::API::Helpers::PackagesHelpers
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
requires :package_id, type: Integer, desc: 'The ID of a package'
|
|
|
|
end
|
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc 'Get all package files' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.8'
|
|
|
|
success ::API::Entities::PackageFile
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get ':id/packages/:package_id/package_files' do
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
2022-02-06 13:15:59 -05:00
|
|
|
package_files = package.installable_package_files
|
2022-03-10 13:09:14 -05:00
|
|
|
.preload_pipelines.order_id_asc
|
2022-01-06 13:13:45 -05:00
|
|
|
|
|
|
|
present paginate(package_files), with: ::API::Entities::PackageFile
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2021-05-07 05:10:27 -04:00
|
|
|
|
|
|
|
desc 'Remove a package file' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.12'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :package_file_id, type: Integer, desc: 'The ID of a package file'
|
|
|
|
end
|
|
|
|
delete ':id/packages/:package_id/package_files/:package_file_id' do
|
|
|
|
authorize_destroy_package!(user_project)
|
|
|
|
|
|
|
|
# We want to make sure the file belongs to the declared package
|
|
|
|
# so we look up the package before looking up the file.
|
|
|
|
package = ::Packages::PackageFinder
|
|
|
|
.new(user_project, params[:package_id]).execute
|
|
|
|
|
|
|
|
not_found! unless package
|
|
|
|
|
2022-02-06 13:15:59 -05:00
|
|
|
package_file = package.installable_package_files
|
|
|
|
.find_by_id(params[:package_file_id])
|
2021-05-07 05:10:27 -04:00
|
|
|
|
|
|
|
not_found! unless package_file
|
|
|
|
|
2022-02-03 19:13:53 -05:00
|
|
|
destroy_conditionally!(package_file) do |package_file|
|
|
|
|
package_file.pending_destruction!
|
|
|
|
end
|
2021-05-07 05:10:27 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|