Skip to content

Commit

Permalink
Allow SpaceApplicationSupporter to cancel deployments.
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Thun <[email protected]>
  • Loading branch information
will-gant and philippthun committed Jun 23, 2021
1 parent 110d3ed commit 348743f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/v3/deployments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def show
def cancel
deployment = DeploymentModel.find(guid: hashed_params[:guid])

resource_not_found!(:deployment) unless deployment && permission_queryer.can_write_to_space?(deployment.app.space_guid)
resource_not_found!(:deployment) unless deployment && permission_queryer.untrusted_can_write_to_space?(deployment.app.space_guid)

begin
DeploymentCancel.cancel(deployment: deployment, user_audit_info: user_audit_info)
Expand Down
3 changes: 2 additions & 1 deletion docs/v3/source/includes/resources/deployments/_cancel.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ HTTP/1.1 200 OK
`POST /v3/deployments/:guid/actions/cancel`

#### Permitted roles
|
Roles | Notes
--- | ---
Admin |
Space Developer |
Space Application Supporter | Experimental |
45 changes: 30 additions & 15 deletions spec/request/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1392,29 +1392,44 @@ def json_for_deployment(deployment, app_model, droplet, status_value, status_rea
describe 'POST /v3/deployments/:guid/actions/cancel' do
context 'when the deployment is running and has a previous droplet' do
let(:old_droplet) { VCAP::CloudController::DropletModel.make(app: app_model, process_types: { 'web' => 'run' }) }

it 'changes the deployment status_value CANCELING and rolls the droplet back' do
deployment = VCAP::CloudController::DeploymentModelTestFactory.make(
let(:deployment) {
VCAP::CloudController::DeploymentModelTestFactory.make(
app: app_model,
droplet: droplet,
previous_droplet: old_droplet
)
}

post "/v3/deployments/#{deployment.guid}/actions/cancel", {}.to_json, user_header
expect(last_response.status).to eq(200), last_response.body
context 'as a SpaceDeveloper' do
it 'succeeds' do
post "/v3/deployments/#{deployment.guid}/actions/cancel", {}.to_json, user_header
expect(last_response.status).to eq(200), last_response.body
expect(last_response.body).to be_empty
end

expect(last_response.body).to be_empty
deployment.reload
expect(deployment.status_value).to eq(VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE)
expect(deployment.status_reason).to eq(VCAP::CloudController::DeploymentModel::CANCELING_STATUS_REASON)
it 'changes the deployment status_value CANCELING and rolls the droplet back' do
post "/v3/deployments/#{deployment.guid}/actions/cancel", {}.to_json, user_header
deployment.reload
expect(deployment.status_value).to eq(VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE)
expect(deployment.status_reason).to eq(VCAP::CloudController::DeploymentModel::CANCELING_STATUS_REASON)
expect(app_model.reload.droplet).to eq(old_droplet)

require 'cloud_controller/deployment_updater/scheduler'
VCAP::CloudController::DeploymentUpdater::Updater.new(deployment, Steno.logger('blah')).cancel
deployment.reload
expect(deployment.status_value).to eq(VCAP::CloudController::DeploymentModel::FINALIZED_STATUS_VALUE)
expect(deployment.status_reason).to eq(VCAP::CloudController::DeploymentModel::CANCELED_STATUS_REASON)
end
end

expect(app_model.reload.droplet).to eq(old_droplet)
context 'as a SpaceApplicationSupporter' do
let(:user) { make_application_supporter_for_space(space) }

require 'cloud_controller/deployment_updater/scheduler'
VCAP::CloudController::DeploymentUpdater::Updater.new(deployment, Steno.logger('blah')).cancel
deployment.reload
expect(deployment.status_value).to eq(VCAP::CloudController::DeploymentModel::FINALIZED_STATUS_VALUE)
expect(deployment.status_reason).to eq(VCAP::CloudController::DeploymentModel::CANCELED_STATUS_REASON)
it 'succeeds' do
post "/v3/deployments/#{deployment.guid}/actions/cancel", {}.to_json, user_header
expect(last_response.status).to eq(200), last_response.body
expect(last_response.body).to be_empty
end
end
end
end
Expand Down

0 comments on commit 348743f

Please sign in to comment.