diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /app/services/ci/deployments/destroy_service.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'app/services/ci/deployments/destroy_service.rb')
-rw-r--r-- | app/services/ci/deployments/destroy_service.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/services/ci/deployments/destroy_service.rb b/app/services/ci/deployments/destroy_service.rb new file mode 100644 index 00000000000..ac51fa55537 --- /dev/null +++ b/app/services/ci/deployments/destroy_service.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Ci + module Deployments + class DestroyService < BaseService + def execute(deployment) + raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_deployment, deployment) + + return ServiceResponse.error(message: 'Cannot destroy running deployment') if deployment&.running? + return ServiceResponse.error(message: 'Deployment currently deployed to environment') if deployment&.last? + + project.destroy_deployment_by_id(deployment) + + ServiceResponse.success(message: 'Deployment destroyed') + end + end + end +end |