Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate short url with workspace info #8719

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8719.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Generate short url with workspace info ([#8719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8719))
7 changes: 6 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/share/public/services/share_menu_manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ShareMenuManager {
...options,
menuItems,
post: core.http.post,
basePath: core.http.basePath.get(),
basePath: core.http.basePath.getBasePath(),
});
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}"`
Expand Down
Loading