2020-07-08 23:09:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class Package < Grape::Entity
|
|
|
|
include ::API::Helpers::RelatedResourcesHelpers
|
2022-10-24 05:11:03 -04:00
|
|
|
include ::Routing::PackagesHelper
|
2020-07-08 23:09:01 -04:00
|
|
|
extend ::API::Entities::EntityHelpers
|
|
|
|
|
|
|
|
expose :id
|
2020-09-24 14:09:51 -04:00
|
|
|
|
|
|
|
expose :name do |package|
|
|
|
|
if package.conan?
|
|
|
|
package.conan_recipe
|
|
|
|
else
|
|
|
|
package.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :conan_package_name, if: ->(package) { package.conan? } do |package|
|
|
|
|
package.name
|
|
|
|
end
|
|
|
|
|
2020-07-08 23:09:01 -04:00
|
|
|
expose :version
|
|
|
|
expose :package_type
|
2021-05-12 05:10:19 -04:00
|
|
|
expose :status
|
2020-07-08 23:09:01 -04:00
|
|
|
|
|
|
|
expose :_links do
|
2022-10-24 05:11:03 -04:00
|
|
|
expose :web_path do |package|
|
|
|
|
package_path(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
|
2022-09-14 14:12:48 -04:00
|
|
|
expose :last_downloaded_at
|
2020-07-08 23:09:01 -04:00
|
|
|
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
|
|
|
|
|
2020-11-16 19:09:16 -05:00
|
|
|
expose :pipeline, if: ->(package) { package.original_build_info }, using: Package::Pipeline
|
|
|
|
expose :pipelines, if: ->(package) { package.pipelines.present? }, using: Package::Pipeline
|
2020-07-08 23:09:01 -04:00
|
|
|
|
2020-09-03 20:09:08 -04:00
|
|
|
expose :versions, using: ::API::Entities::PackageVersion, unless: ->(_, opts) { opts[:collection] }
|
2020-07-08 23:09:01 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_path
|
|
|
|
object.project.full_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|