diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-05-10 20:02:00 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2019-05-24 12:04:35 +0300 |
commit | 6ef27f77447ad389ca9b508909964c127fd38eeb (patch) | |
tree | efd9aa2c7a1b029acc798fba446c1434ba9aa6bf /app/serializers/deployment_entity.rb | |
parent | a96b9ebfbeb7926fdee632f0eeef9e09a63bec21 (diff) |
Expose build environment latest deployable name and path
Diffstat (limited to 'app/serializers/deployment_entity.rb')
-rw-r--r-- | app/serializers/deployment_entity.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb index 2bafcee0109..943c707218d 100644 --- a/app/serializers/deployment_entity.rb +++ b/app/serializers/deployment_entity.rb @@ -22,8 +22,18 @@ class DeploymentEntity < Grape::Entity expose :last? expose :user, using: UserEntity + 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 :deployable, using: JobEntity, 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? } @@ -36,4 +46,13 @@ class DeploymentEntity < Grape::Entity def can_create_deployment? can?(request.current_user, :create_deployment, request.project) end + + 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 end |