2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-21 06:21:50 -04:00
|
|
|
class ContainerRepositoryEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
2020-05-25 17:08:00 -04:00
|
|
|
expose :id, :name, :path, :location, :created_at, :status, :tags_count
|
2020-10-02 08:09:03 -04:00
|
|
|
expose :expiration_policy_started_at, as: :cleanup_policy_started_at
|
2017-09-21 06:21:50 -04:00
|
|
|
|
|
|
|
expose :tags_path do |repository|
|
|
|
|
project_registry_repository_tags_path(project, repository, format: :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :destroy_path, if: -> (*) { can_destroy? } do |repository|
|
|
|
|
project_container_registry_path(project, repository, format: :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :repository, :object
|
|
|
|
|
|
|
|
def project
|
2019-10-17 08:07:33 -04:00
|
|
|
request.respond_to?(:project) ? request.project : object.project
|
2017-09-21 06:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_destroy?
|
|
|
|
can?(request.current_user, :update_container_image, project)
|
|
|
|
end
|
|
|
|
end
|