-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Fix Custom Threshold Rule `ViewInAppUrl` does not hon…
…or space (#201793) (#203736) # Backport This will backport the following commits from `main` to `8.x`: - [Fix Custom Threshold Rule `ViewInAppUrl` does not honor space (#201793)](#201793) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Anton Dosov","email":"anton.dosov@elastic.co"},"sourceCommit":{"committedDate":"2024-12-11T09:39:01Z","message":"Fix Custom Threshold Rule `ViewInAppUrl` does not honor space (#201793)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/201378\r\nFix https://github.com/elastic/kibana/issues/201333\r\n\r\n- [Share] Allow to pass `spaceId` to `getRedirectUrl` to build a URL\r\nwith a specific `spaceId`\r\n- Fix Custom Threshold Rule ViewInAppUrl does not honor Space\r\n\r\n---------\r\n\r\nCo-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>","sha":"f1f3a4fddd34a08e33d2778a09f2166d6d1b02a0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:SharedUX","ci:project-deploy-observability","Team:obs-ux-management","backport:version","v8.18.0","v8.17.1"],"title":"Fix Custom Threshold Rule `ViewInAppUrl` does not honor space","number":201793,"url":"https://github.com/elastic/kibana/pull/201793","mergeCommit":{"message":"Fix Custom Threshold Rule `ViewInAppUrl` does not honor space (#201793)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/201378\r\nFix https://github.com/elastic/kibana/issues/201333\r\n\r\n- [Share] Allow to pass `spaceId` to `getRedirectUrl` to build a URL\r\nwith a specific `spaceId`\r\n- Fix Custom Threshold Rule ViewInAppUrl does not honor Space\r\n\r\n---------\r\n\r\nCo-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>","sha":"f1f3a4fddd34a08e33d2778a09f2166d6d1b02a0"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201793","number":201793,"mergeCommit":{"message":"Fix Custom Threshold Rule `ViewInAppUrl` does not honor space (#201793)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/201378\r\nFix https://github.com/elastic/kibana/issues/201333\r\n\r\n- [Share] Allow to pass `spaceId` to `getRedirectUrl` to build a URL\r\nwith a specific `spaceId`\r\n- Fix Custom Threshold Rule ViewInAppUrl does not honor Space\r\n\r\n---------\r\n\r\nCo-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>","sha":"f1f3a4fddd34a08e33d2778a09f2166d6d1b02a0"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
- Loading branch information
1 parent
55ac8cf
commit e0f9cf7
Showing
19 changed files
with
421 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/plugins/share/common/url_service/locators/redirect/space_url_parser.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { addSpaceIdToPath } from './space_url_parser'; | ||
|
||
describe('addSpaceIdToPath', () => { | ||
test('handles no parameters', () => { | ||
expect(addSpaceIdToPath()).toEqual(`/`); | ||
}); | ||
|
||
test('it adds to the basePath correctly', () => { | ||
expect(addSpaceIdToPath('/my/base/path', 'url-context')).toEqual('/my/base/path/s/url-context'); | ||
}); | ||
|
||
test('it appends the requested path to the end of the url context', () => { | ||
expect(addSpaceIdToPath('/base', 'context', '/final/destination')).toEqual( | ||
'/base/s/context/final/destination' | ||
); | ||
}); | ||
|
||
test('it replaces existing space identifiers', () => { | ||
expect(addSpaceIdToPath('/my/base/path/s/old-space/', 'new-space')).toEqual( | ||
'/my/base/path/s/new-space' | ||
); | ||
|
||
expect(addSpaceIdToPath('/my/base/path/s/old-space-no-trailing', 'new-space')).toEqual( | ||
'/my/base/path/s/new-space' | ||
); | ||
}); | ||
|
||
test('it removes existing space identifier when spaceId is default', () => { | ||
expect(addSpaceIdToPath('/my/base/path/s/old-space', 'default')).toEqual('/my/base/path'); | ||
expect(addSpaceIdToPath('/my/base/path/s/old-space')).toEqual('/my/base/path'); | ||
}); | ||
|
||
test('it throws an error when the requested path does not start with a slash', () => { | ||
expect(() => { | ||
addSpaceIdToPath('', '', 'foo'); | ||
}).toThrowErrorMatchingInlineSnapshot(`"path must start with a /"`); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/plugins/share/common/url_service/locators/redirect/space_url_parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export function addSpaceIdToPath( | ||
basePath: string = '/', | ||
spaceId: string = '', | ||
requestedPath: string = '' | ||
): string { | ||
if (requestedPath && !requestedPath.startsWith('/')) { | ||
throw new Error(`path must start with a /`); | ||
} | ||
|
||
if (basePath.includes('/s/')) { | ||
// If the base path already contains a space identifier, remove it | ||
basePath = basePath.replace(/\/s\/[^/]+/, ''); | ||
} | ||
|
||
const normalizedBasePath = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath; | ||
|
||
if (spaceId && spaceId !== 'default') { | ||
return `${normalizedBasePath}/s/${spaceId}${requestedPath}`; | ||
} | ||
|
||
return `${normalizedBasePath}${requestedPath}` || '/'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.