diff --git a/changelogs/fragments/8719.yml b/changelogs/fragments/8719.yml new file mode 100644 index 000000000000..e0e6d17e26a4 --- /dev/null +++ b/changelogs/fragments/8719.yml @@ -0,0 +1,2 @@ +fix: +- Generate short url with workspace info ([#8719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8719)) \ No newline at end of file diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 73d00b2f6f11..1fa49a0a0196 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -373,7 +373,12 @@ export { } from './metrics'; export { AppCategory, WorkspaceAttribute, PermissionModeId } from '../types'; -export { DEFAULT_APP_CATEGORIES, WORKSPACE_TYPE, DEFAULT_NAV_GROUPS } from '../utils'; +export { + DEFAULT_APP_CATEGORIES, + WORKSPACE_TYPE, + DEFAULT_NAV_GROUPS, + WORKSPACE_PATH_PREFIX, +} from '../utils'; export { SavedObject, diff --git a/src/plugins/share/public/services/share_menu_manager.tsx b/src/plugins/share/public/services/share_menu_manager.tsx index 5d8210b48c5b..da76f8f3897c 100644 --- a/src/plugins/share/public/services/share_menu_manager.tsx +++ b/src/plugins/share/public/services/share_menu_manager.tsx @@ -56,7 +56,7 @@ export class ShareMenuManager { ...options, menuItems, post: core.http.post, - basePath: core.http.basePath.get(), + basePath: core.http.basePath.getBasePath(), }); }, }; diff --git a/src/plugins/share/server/routes/lib/short_url_assert_valid.test.ts b/src/plugins/share/server/routes/lib/short_url_assert_valid.test.ts index 7f9744119c73..c272185fed59 100644 --- a/src/plugins/share/server/routes/lib/short_url_assert_valid.test.ts +++ b/src/plugins/share/server/routes/lib/short_url_assert_valid.test.ts @@ -49,6 +49,7 @@ describe('shortUrlAssertValid()', () => { ['path with an extra leading slash', '///app/opensearch-dashboards', HOSTNAME_ERROR], // parser detects '' as the hostname ['path without app', '/foo/opensearch-dashboards', PATH_ERROR], // fails because first path part is not 'app' ['path without appId', '/app/', PATH_ERROR], // fails because there is only one path part (leading and trailing slashes are trimmed) + '/w/app/dashboards', // fails because it is not a standard workspace path ]; invalid.forEach(([desc, url, error]) => { @@ -67,6 +68,7 @@ describe('shortUrlAssertValid()', () => { '/app/some?with=query', '/app/some?with=query#and-a-hash', '/app/some/deeper?with=query#and-a-hash', + '/w/workspaceid/app/foo', ]; valid.forEach((url) => { diff --git a/src/plugins/share/server/routes/lib/short_url_assert_valid.ts b/src/plugins/share/server/routes/lib/short_url_assert_valid.ts index b6514a68e6f6..248249e33225 100644 --- a/src/plugins/share/server/routes/lib/short_url_assert_valid.ts +++ b/src/plugins/share/server/routes/lib/short_url_assert_valid.ts @@ -31,6 +31,7 @@ import { parse } from 'url'; import { trim } from 'lodash'; import Boom from '@hapi/boom'; +import { WORKSPACE_PATH_PREFIX } from '../../../../../core/server'; export function shortUrlAssertValid(url: string) { const { protocol, hostname, pathname } = parse( @@ -47,7 +48,13 @@ export function shortUrlAssertValid(url: string) { throw Boom.notAcceptable(`Short url targets cannot have a hostname, found "${hostname}"`); } - const pathnameParts = trim(pathname === null ? undefined : pathname, '/').split('/'); + let pathnameParts = trim(pathname === null ? undefined : pathname, '/').split('/'); + + // Workspace introduced paths like `/w/${workspaceId}/app` + // ignore the first 2 elements if it starts with /w + if (`/${pathnameParts[0]}` === WORKSPACE_PATH_PREFIX) { + pathnameParts = pathnameParts.slice(2); + } if (pathnameParts[0] !== 'app' || !pathnameParts[1]) { throw Boom.notAcceptable( `Short url target path must be in the format "/app/{{appId}}", found "${pathname}"`