Extract logic who created deployment into Deployment#deployed_by
Prefer the deployable user over the deployment user. Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/66037.
This commit is contained in:
parent
51c19691e4
commit
d86b77bf20
5 changed files with 42 additions and 3 deletions
|
@ -162,6 +162,14 @@ class Deployment < ApplicationRecord
|
|||
deployed_at&.to_time&.in_time_zone&.to_s(:medium)
|
||||
end
|
||||
|
||||
def deployed_by
|
||||
# We use deployable's user if available because Ci::PlayBuildService
|
||||
# does not update the deployment's user, just the one for the deployable.
|
||||
# TODO: use deployment's user once https://gitlab.com/gitlab-org/gitlab-ce/issues/66442
|
||||
# is completed.
|
||||
deployable&.user || user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ref_path
|
||||
|
|
|
@ -21,7 +21,7 @@ class DeploymentEntity < Grape::Entity
|
|||
expose :finished_at
|
||||
expose :tag
|
||||
expose :last?
|
||||
expose :user, using: UserEntity
|
||||
expose :deployed_by, as: :user, using: UserEntity
|
||||
|
||||
expose :deployable do |deployment, opts|
|
||||
deployment.deployable.yield_self do |deployable|
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
.flex-truncate-child
|
||||
= link_to [@project.namespace.becomes(Namespace), @project, deployment.deployable], class: 'build-link' do
|
||||
#{deployment.deployable.name} (##{deployment.deployable.id})
|
||||
- if deployment.user
|
||||
- if deployment.deployed_by
|
||||
%div
|
||||
by
|
||||
= user_avatar(user: deployment.user, size: 20, css_class: "mr-0 float-none")
|
||||
= user_avatar(user: deployment.deployed_by, size: 20, css_class: "mr-0 float-none")
|
||||
|
||||
.table-section.section-15{ role: 'gridcell' }
|
||||
.table-mobile-header{ role: 'rowheader' }= _("Created")
|
||||
|
|
5
changelogs/unreleased/66037-deployment-user.yml
Normal file
5
changelogs/unreleased/66037-deployment-user.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Return correct user for manual deployments
|
||||
merge_request: 32004
|
||||
author:
|
||||
type: fixed
|
|
@ -322,4 +322,30 @@ describe Deployment do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#deployed_by' do
|
||||
it 'returns the deployment user if there is no deployable' do
|
||||
deployment_user = create(:user)
|
||||
deployment = create(:deployment, deployable: nil, user: deployment_user)
|
||||
|
||||
expect(deployment.deployed_by).to eq(deployment_user)
|
||||
end
|
||||
|
||||
it 'returns the deployment user if the deployable have no user' do
|
||||
deployment_user = create(:user)
|
||||
build = create(:ci_build, user: nil)
|
||||
deployment = create(:deployment, deployable: build, user: deployment_user)
|
||||
|
||||
expect(deployment.deployed_by).to eq(deployment_user)
|
||||
end
|
||||
|
||||
it 'returns the deployable user if there is one' do
|
||||
build_user = create(:user)
|
||||
deployment_user = create(:user)
|
||||
build = create(:ci_build, user: build_user)
|
||||
deployment = create(:deployment, deployable: build, user: deployment_user)
|
||||
|
||||
expect(deployment.deployed_by).to eq(build_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue