Skip to content

Commit

Permalink
Add endpoint to view shared spaces of a route
Browse files Browse the repository at this point in the history
  • Loading branch information
2 people authored and MerricdeLauney committed May 31, 2022
1 parent 46616f4 commit f631935
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/v3/routes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ def unshare_route
unprocessable!(e.message)
end

def relationships_shared_routes
FeatureFlag.raise_unless_enabled!(:route_sharing)

render status: :ok, json: Presenters::V3::ToManyRelationshipPresenter.new(
"routes/#{route.guid}", route.shared_spaces, 'shared_spaces', build_related: false)
end

def index_destinations
message = RouteShowMessage.from_params({ guid: hashed_params['guid'] })
unprocessable!(message.errors.full_messages) unless message.valid?
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
post '/routes', to: 'routes#create'
post '/routes/:guid/relationships/shared_spaces', to: 'routes#share_routes'
delete '/routes/:guid/relationships/shared_spaces/:space_guid', to: 'routes#unshare_route'
get '/routes/:guid/relationships/shared_spaces', to: 'routes#relationships_shared_routes'
patch '/routes/:guid', to: 'routes#update'
delete '/routes/:guid', to: 'routes#destroy'
get '/apps/:guid/routes', to: 'routes#index_by_app'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,51 @@ HTTP/1.1 204 No Content
Admin |
Space Developer |
Space Supporter |


## Lists shared spaces relationship (experimental)

Lists the spaces that the route has been shared to.

```
Example Request
```

```shell
curl "https://api.example.org/v3/routes/[guid]/relationships/shared_spaces" \
-H "Authorization: bearer [token]" \
-H "Content-type: application/json"
```

```http
HTTP/1.1 200 OK
Content-Type: application/json

{
"data": {
[
"guid": "space-one-guid",
"guid": "space-two-guid"
]
},
"links": {
"self": {
"href":"http://api.example.com/v3/routes/[guid]/relationships/shared_spaces"
},
}
}
```

#### Permitted roles

|
--- |
Admin |
Admin Read-Only |
Global Auditor |
Org Auditor |
Org Manager |
Space Auditor |
Space Developer |
Space Manager |
Space Supporter
66 changes: 66 additions & 0 deletions spec/request/routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,72 @@
end
end

describe 'GET /v3/routes/:guid/relationships/shared_spaces' do
let(:api_call) { lambda { |user_headers| get "/v3/routes/#{guid}/relationships/shared_spaces", nil, user_headers } }
let(:target_space_1) { VCAP::CloudController::Space.make(organization: org) }
let(:route) {
route = VCAP::CloudController::Route.make(space: space)
route.add_shared_space(target_space_1)
route
}
let(:guid) { route.guid }
let(:space_dev_headers) do
org.add_user(user)
space.add_developer(user)
headers_for(user)
end
let!(:feature_flag) do
VCAP::CloudController::FeatureFlag.make(name: 'route_sharing', enabled: true, error_message: nil)
end

before do
org.add_user(user)
target_space_1.add_developer(user)
end

describe 'permissions' do
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS do
let(:expected_codes_and_responses) do
h = Hash.new(code: 200, response_object: {
data: [
{
guid: target_space_1.guid
}
],
links: {
self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/routes\/#{route.guid}\/relationships\/shared_spaces) },
}
})

h['org_billing_manager'] = { code: 404 }
h['no_role'] = { code: 404 }
h
end
end
end

describe 'when route_sharing flag is disabled' do
before do
feature_flag.enabled = false
feature_flag.save
end

it 'makes users unable to unshare routes' do
api_call.call(space_dev_headers)

expect(last_response).to have_status_code(403)
expect(parsed_response['errors']).to include(
include(
{
'detail' => 'Feature Disabled: route_sharing',
'title' => 'CF-FeatureDisabled',
'code' => 330002,
})
)
end
end
end

describe 'errors while sharing' do
# isolation segments?
end
Expand Down

0 comments on commit f631935

Please sign in to comment.