Skip to content

Commit

Permalink
fix: generate short url with workspace info (#8719) (#8721)
Browse files Browse the repository at this point in the history
* fix: generate short url with workspace info



* Changeset file for PR #8719 created/updated

---------



(cherry picked from commit 54fd87d)

Signed-off-by: SuZhou-Joe <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent a02cda9 commit b4e9f56
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
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

0 comments on commit b4e9f56

Please sign in to comment.