Skip to content

Commit

Permalink
Allow space application supporter to get and list 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 83913d2 commit 3bf5b24
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/controllers/v3/deployments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index
dataset = if permission_queryer.can_read_globally?
DeploymentListFetcher.fetch_all(message)
else
DeploymentListFetcher.fetch_for_spaces(message, space_guids: permission_queryer.readable_space_guids)
DeploymentListFetcher.fetch_for_spaces(message, space_guids: permission_queryer.readable_application_supporter_space_guids)
end

render status: :ok, json: Presenters::V3::PaginatedListPresenter.new(
Expand Down Expand Up @@ -73,7 +73,7 @@ def show
deployment = DeploymentModel.find(guid: hashed_params[:guid])

resource_not_found!(:deployment) unless deployment &&
permission_queryer.can_read_from_space?(deployment.app.space.guid, deployment.app.space.organization.guid)
permission_queryer.untrusted_can_read_from_space?(deployment.app.space.guid, deployment.app.space.organization.guid)

render status: :ok, json: Presenters::V3::DeploymentPresenter.new(deployment)
end
Expand Down
3 changes: 2 additions & 1 deletion docs/v3/source/includes/resources/deployments/_get.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Content-Type: application/json
`GET /v3/deployments/:guid`

#### Permitted roles
|
Roles | Notes
--- | ---
Admin |
Admin Read-Only |
Expand All @@ -34,3 +34,4 @@ Org Manager |
Space Auditor |
Space Developer |
Space Manager |
Space Application Supporter | Experimental |
3 changes: 2 additions & 1 deletion docs/v3/source/includes/resources/deployments/_list.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Name | Type | Description
**updated_ats** (*experimental*)| _[timestamp](#timestamps)_ | Timestamp to filter by. When filtering on equality, several comma-delimited timestamps may be passed. Also supports filtering with [relational operators](#relational-operators-experimental)

#### Permitted roles
|
Roles | Notes
--- | ---
Admin |
Admin Read-Only |
Expand All @@ -52,3 +52,4 @@ Org Manager |
Space Auditor |
Space Developer |
Space Manager |
Space Application Supporter | Experimental |
42 changes: 29 additions & 13 deletions spec/request/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,15 @@

describe 'GET /v3/deployments/:guid' do
let(:old_droplet) { VCAP::CloudController::DropletModel.make }

it 'should get and display the deployment' do
deployment = VCAP::CloudController::DeploymentModelTestFactory.make(
let(:deployment) {
VCAP::CloudController::DeploymentModelTestFactory.make(
app: app_model,
droplet: droplet,
previous_droplet: old_droplet
)

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({
}
let(:expected_response) {
{
'guid' => deployment.guid,
'status' => {
'value' => VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE,
Expand Down Expand Up @@ -909,7 +905,27 @@
'method' => 'POST'
}
}
})
}
}

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)
end

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

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)
end
end
end

Expand Down Expand Up @@ -1097,7 +1113,7 @@ def json_for_deployment(deployment, app_model, droplet, status_value, status_rea
h.freeze
end

it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS
it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS + ['space_application_supporter']

context 'pagination' do
let(:pagination_hsh) do
Expand Down Expand Up @@ -1146,7 +1162,7 @@ def json_for_deployment(deployment, app_model, droplet, status_value, status_rea
h.freeze
end

it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS
it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS + ['space_application_supporter']

context 'pagination' do
let(:pagination_hsh) do
Expand Down Expand Up @@ -1188,7 +1204,7 @@ def json_for_deployment(deployment, app_model, droplet, status_value, status_rea
h.freeze
end

it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS
it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS + ['space_application_supporter']

context 'pagination' do
let(:pagination_hsh) do
Expand Down
6 changes: 6 additions & 0 deletions spec/support/model_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def make_developer_for_space(space)
user
end

def make_application_supporter_for_space(space)
user = make_user_for_org space.organization
space.add_application_supporter user
user
end

def make_auditor_for_space(space)
user = make_user_for_org(space.organization)
space.add_auditor(user)
Expand Down

0 comments on commit 3bf5b24

Please sign in to comment.