debian-mirror-gitlab/app/serializers/deployment_entity.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class DeploymentEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :iid
expose :sha
expose :ref do
expose :name do |deployment|
deployment.ref
end
expose :ref_path do |deployment|
2017-09-10 17:25:29 +05:30
project_tree_path(deployment.project, id: deployment.ref)
2017-08-17 22:00:37 +05:30
end
end
expose :created_at
expose :tag
expose :last?
expose :user, using: UserEntity
2019-09-04 21:01:54 +05:30
expose :deployable do |deployment, opts|
deployment.deployable.yield_self do |deployable|
if include_details?
JobEntity.represent(deployable, opts)
elsif can_read_deployables?
{ name: deployable.name,
build_path: project_job_path(deployable.project, deployable) }
end
end
end
expose :commit, using: CommitEntity, if: -> (*) { include_details? }
expose :manual_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? }
expose :scheduled_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? }
2019-03-02 22:35:43 +05:30
private
2019-09-04 21:01:54 +05:30
def include_details?
options.fetch(:deployment_details, true)
end
2019-03-02 22:35:43 +05:30
def can_create_deployment?
can?(request.current_user, :create_deployment, request.project)
end
2019-09-04 21:01:54 +05:30
def can_read_deployables?
##
# We intentionally do not check `:read_build, deployment.deployable`
# because it triggers a policy evaluation that involves multiple
# Gitaly calls that might not be cached.
#
can?(request.current_user, :read_build, request.project)
end
2017-08-17 22:00:37 +05:30
end