2020-07-08 23:09:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class Package < Grape::Entity
|
|
|
|
include ::API::Helpers::RelatedResourcesHelpers
|
|
|
|
extend ::API::Entities::EntityHelpers
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
|
|
|
expose :version
|
|
|
|
expose :package_type
|
|
|
|
|
|
|
|
expose :_links do
|
|
|
|
expose :web_path do |package|
|
2020-07-21 08:09:30 -04:00
|
|
|
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
|
2020-07-08 23:09:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
|
|
|
|
expose_url api_v4_projects_packages_path(package_id: package.id, id: package.project_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :created_at
|
|
|
|
expose :project_id, if: ->(_, opts) { opts[:group] }
|
|
|
|
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
|
|
|
|
expose :tags
|
|
|
|
|
|
|
|
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
|
|
|
|
|
|
|
|
expose :versions, using: ::API::Entities::PackageVersion
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_path
|
|
|
|
object.project.full_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|