Skip to content

Commit

Permalink
Allow SpaceApplicationSupporter to create 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 10, 2021
1 parent 3bf5b24 commit 2519eb2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 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 @@ -33,7 +33,7 @@ def create
unprocessable!(message.errors.full_messages) unless message.valid?

app = AppModel.find(guid: message.app_guid)
unprocessable!('Unable to use app. Ensure that the app exists and you have access to it.') unless app && permission_queryer.can_write_to_space?(app.space.guid)
unprocessable!('Unable to use app. Ensure that the app exists and you have access to it.') unless app && permission_queryer.untrusted_can_write_to_space?(app.space.guid)
unprocessable!('Cannot create deployment from a revision for an app without revisions enabled') if message.revision_guid && !app.revisions_enabled

begin
Expand Down
67 changes: 43 additions & 24 deletions spec/request/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,8 @@

describe 'POST /v3/deployments' do
context 'when a droplet is not supplied with the request' do
let(:create_request) do
let(:expected_response) {
{
relationships: {
app: {
data: {
guid: app_model.guid
}
},
}
}
end

it 'should create a deployment object using the current droplet from the app' do
post '/v3/deployments', create_request.to_json, user_header
expect(last_response.status).to eq(201)

deployment = VCAP::CloudController::DeploymentModel.last

expect(parsed_response).to be_a_response_like({
'guid' => deployment.guid,
'status' => {
'value' => VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE,
Expand Down Expand Up @@ -85,7 +68,41 @@
'method' => 'POST'
}
}
})
}
}
let(:create_request) do
{
relationships: {
app: {
data: {
guid: app_model.guid
}
},
}
}
end
let(:deployment) {
VCAP::CloudController::DeploymentModel.last
}

context 'as a SpaceDeveloper' do
it 'should create a deployment object using the current droplet from the app' do
post '/v3/deployments', create_request.to_json, user_header
expect(last_response.status).to eq(201)

expect(parsed_response).to be_a_response_like(expected_response)
end
end

context 'as a SpaceApplicationSupporter' do
let(:user) { make_application_supporter_for_space(space) }

it 'should create a deployment object using the current droplet from the app' do
post '/v3/deployments', create_request.to_json, user_header
expect(last_response.status).to eq(201)

expect(parsed_response).to be_a_response_like(expected_response)
end
end
end

Expand Down Expand Up @@ -908,12 +925,14 @@
}
}

it 'should get and display the deployment' do
get "/v3/deployments/#{deployment.guid}", nil, user_header
expect(last_response.status).to eq(200)
context 'as a SpaceDeveloper' do
it 'should get and display the deployment' do
get "/v3/deployments/#{deployment.guid}", nil, user_header
expect(last_response.status).to eq(200)

parsed_response = MultiJson.load(last_response.body)
expect(parsed_response).to be_a_response_like(expected_response)
parsed_response = MultiJson.load(last_response.body)
expect(parsed_response).to be_a_response_like(expected_response)
end
end

context 'as a SpaceApplicationSupporter' do
Expand Down

0 comments on commit 2519eb2

Please sign in to comment.