diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/api/entities/package.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'lib/api/entities/package.rb')
-rw-r--r-- | lib/api/entities/package.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/api/entities/package.rb b/lib/api/entities/package.rb new file mode 100644 index 00000000000..73473f16da9 --- /dev/null +++ b/lib/api/entities/package.rb @@ -0,0 +1,42 @@ +# 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| + if ::Gitlab.ee? + ::Gitlab::Routing.url_helpers.project_package_path(package.project, package) + end + 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 |