Skip to content

Commit

Permalink
[8.15] Fixed URL hash appending for space next redirect URL (#189204) (
Browse files Browse the repository at this point in the history
…#189251)

# Backport

This will backport the following commits from `main` to `8.15`:
- [Fixed URL hash appending for space next redirect URL
(#189204)](#189204)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"elena-shostak","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-26T08:40:50Z","message":"Fixed
URL hash appending for space next redirect URL (#189204)\n\n##
Summary\r\n\r\nFixed URL hash appending for space next redirect
URL.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n__Fixes:
https://github.com/elastic/kibana/issues/189184__","sha":"3f3713b567c2bb513198593de3092fcf7cb69173","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Security","Feature:Security/Spaces","release_note:skip","backport:prev-minor","v8.16.0"],"title":"Fixed
URL hash appending for space next redirect
URL","number":189204,"url":"https://github.com/elastic/kibana/pull/189204","mergeCommit":{"message":"Fixed
URL hash appending for space next redirect URL (#189204)\n\n##
Summary\r\n\r\nFixed URL hash appending for space next redirect
URL.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n__Fixes:
https://github.com/elastic/kibana/issues/189184__","sha":"3f3713b567c2bb513198593de3092fcf7cb69173"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/189204","number":189204,"mergeCommit":{"message":"Fixed
URL hash appending for space next redirect URL (#189204)\n\n##
Summary\r\n\r\nFixed URL hash appending for space next redirect
URL.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n__Fixes:
https://github.com/elastic/kibana/issues/189184__","sha":"3f3713b567c2bb513198593de3092fcf7cb69173"}}]}]
BACKPORT-->

Co-authored-by: elena-shostak <[email protected]>
  • Loading branch information
kibanamachine and elena-shostak authored Jul 26, 2024
1 parent 7c31f6c commit 975b710
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions x-pack/plugins/spaces/server/routes/views/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ describe('Enter Space view routes', () => {
expectedLocation:
'/mock-server-basepath/app/management/kibana/objects?initialQuery=type:(visualization)',
},
{
query: {
next: '/app/discover#/view/uuid',
},
expectedLocation: '/mock-server-basepath/app/discover#/view/uuid',
},
{
query: {
next: '/app/discover?initialQuery=type:(visualization)#/view/uuid',
},
expectedLocation:
'/mock-server-basepath/app/discover?initialQuery=type:(visualization)#/view/uuid',
},
]) {
const request = httpServerMock.createKibanaRequest({
query,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/spaces/server/routes/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function initSpacesViewsRoutes(deps: ViewRouteDeps) {

return response.redirected({
headers: {
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}`,
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}${normalizedRoute.hash}`,
},
});
} catch (e) {
Expand Down
20 changes: 20 additions & 0 deletions x-pack/test/functional/apps/spaces/enter_space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ export default function enterSpaceFunctionalTests({
await PageObjects.spaceSelector.expectRoute(spaceId, '/app/management/kibana/objects');
});

it('allows user to navigate to different space with provided next route preserving url hash and search', async () => {
const spaceId = 'another-space';

await PageObjects.security.login(undefined, undefined, {
expectSpaceSelector: true,
});

const anchorElement = await PageObjects.spaceSelector.getSpaceCardAnchor(spaceId);
const path = await anchorElement.getAttribute('href');

const pathWithNextRoute = `${path}?next=/app/management/kibana/objects?initialQuery=type:(visualization)#/view`;

await browser.navigateTo(pathWithNextRoute);

await PageObjects.spaceSelector.expectRoute(
spaceId,
'/app/management/kibana/objects?initialQuery=type%3A(visualization)#/view'
);
});

it('allows user to navigate to different space with provided next route, route is normalized', async () => {
const spaceId = 'another-space';

Expand Down

0 comments on commit 975b710

Please sign in to comment.