forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Custom Threshold Rule
ViewInAppUrl
does not honor space (elasti…
…c#201793) ## Summary Close elastic#201378 Fix elastic#201333 - [Share] Allow to pass `spaceId` to `getRedirectUrl` to build a URL with a specific `spaceId` - Fix Custom Threshold Rule ViewInAppUrl does not honor Space --------- Co-authored-by: Maryam Saeidi <[email protected]>
- Loading branch information
1 parent
4511abe
commit f1f3a4f
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.