From 3091b664901ff22d763abbab187e3b12467b9a24 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 4 Dec 2024 17:46:06 +0800 Subject: [PATCH 1/5] fix: fix page hanging when none collaborators for non dashboard admin Signed-off-by: tygao --- .../public/components/workspace_form/utils.test.ts | 7 ++++--- .../public/components/workspace_form/utils.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_form/utils.test.ts b/src/plugins/workspace/public/components/workspace_form/utils.test.ts index aee0a1e1ca56..4f3dc63f9b24 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.test.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.test.ts @@ -11,6 +11,7 @@ import { getNumberOfErrors, isWorkspacePermissionSetting, getPermissionModeName, + EMPTY_PERMISSIONS, } from './utils'; import { WorkspacePermissionMode } from '../../../common/constants'; import { WorkspacePermissionItemType, optionIdToWorkspacePermissionModesMap } from './constants'; @@ -19,9 +20,9 @@ import { WorkspaceFormErrorCode } from './types'; import { PermissionModeId } from '../../../../../core/public'; describe('convertPermissionSettingsToPermissions', () => { - it('should return undefined if permission items not provided', () => { - expect(convertPermissionSettingsToPermissions(undefined)).toBeUndefined(); - expect(convertPermissionSettingsToPermissions([])).toBeUndefined(); + it('should return empty permission object if permission items are not provided', () => { + expect(convertPermissionSettingsToPermissions(undefined)).toBe(EMPTY_PERMISSIONS); + expect(convertPermissionSettingsToPermissions([])).toBe(EMPTY_PERMISSIONS); }); it('should not add duplicate users and groups', () => { diff --git a/src/plugins/workspace/public/components/workspace_form/utils.ts b/src/plugins/workspace/public/components/workspace_form/utils.ts index 1233bfbc0d53..a756541004c4 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.ts @@ -37,6 +37,13 @@ export const isValidFormTextInput = (input?: string) => { return typeof input === 'string' && regex.test(input); }; +export const EMPTY_PERMISSIONS = { + library_read: {}, + library_write: {}, + read: {}, + write: {}, +}; + export const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => { let numberOfErrors = 0; if (formErrors.name) { @@ -104,7 +111,8 @@ export const convertPermissionSettingsToPermissions = ( permissionItems: WorkspacePermissionSetting[] | undefined ) => { if (!permissionItems || permissionItems.length === 0) { - return undefined; + // Workspace object should always have permissions, set it as an empty object here instead of undefined. + return EMPTY_PERMISSIONS; } return permissionItems.reduce((previous, current) => { current.modes.forEach((mode) => { From c7a8ddb4ca0c0a030b539dc324a3ea1d73dfe419 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 5 Dec 2024 10:59:19 +0800 Subject: [PATCH 2/5] add const type Signed-off-by: tygao --- .../workspace/public/components/workspace_form/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_form/utils.ts b/src/plugins/workspace/public/components/workspace_form/utils.ts index a756541004c4..660e4e9b2661 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.ts @@ -37,12 +37,12 @@ export const isValidFormTextInput = (input?: string) => { return typeof input === 'string' && regex.test(input); }; -export const EMPTY_PERMISSIONS = { +export const EMPTY_PERMISSIONS: SavedObjectPermissions = { library_read: {}, library_write: {}, read: {}, write: {}, -}; +} as const; export const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => { let numberOfErrors = 0; From e46a36fb2aefc542a51453e4254b77a852602db8 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:03:46 +0000 Subject: [PATCH 3/5] Changeset file for PR #9004 created/updated --- changelogs/fragments/9004.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/9004.yml diff --git a/changelogs/fragments/9004.yml b/changelogs/fragments/9004.yml new file mode 100644 index 000000000000..0ab1899240e2 --- /dev/null +++ b/changelogs/fragments/9004.yml @@ -0,0 +1,2 @@ +fix: +- Fix page hanging when none collaborators for non dashboard admin ([#9004](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9004)) \ No newline at end of file From c4e6147a566dd6c41e3adf32d901cde68de8df9b Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:05:44 +0000 Subject: [PATCH 4/5] Changeset file for PR #9004 created/updated --- changelogs/fragments/9004.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/9004.yml b/changelogs/fragments/9004.yml index 0ab1899240e2..1104122bd989 100644 --- a/changelogs/fragments/9004.yml +++ b/changelogs/fragments/9004.yml @@ -1,2 +1,2 @@ fix: -- Fix page hanging when none collaborators for non dashboard admin ([#9004](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9004)) \ No newline at end of file +- Fix workspace page hanging with none collaborators for non dashboard admin ([#9004](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9004)) \ No newline at end of file From b9b7eddfc20e823298fd07133e821209ef1f87a9 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 11 Dec 2024 14:11:21 +0800 Subject: [PATCH 5/5] update empty permissions when permission is disabled for workspace detail page Signed-off-by: tygao --- .../public/components/workspace_detail_app.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_detail_app.tsx b/src/plugins/workspace/public/components/workspace_detail_app.tsx index 7304c4d19a47..6a8ee0ad630e 100644 --- a/src/plugins/workspace/public/components/workspace_detail_app.tsx +++ b/src/plugins/workspace/public/components/workspace_detail_app.tsx @@ -117,7 +117,12 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailPropsWithOnAppLeave) => result = await workspaceClient.update(currentWorkspace.id, attributes, { dataSources: selectedDataSourceIds, - permissions: convertPermissionSettingsToPermissions(permissionSettings), + // If user updates workspace when permission is disabled, the permission settings will be cleared + ...(isPermissionEnabled + ? { + permissions: convertPermissionSettingsToPermissions(permissionSettings), + } + : {}), }); setIsFormSubmitting(false); if (result?.success) { @@ -141,7 +146,13 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailPropsWithOnAppLeave) => return; } }, - [isFormSubmitting, currentWorkspace, notifications?.toasts, workspaceClient] + [ + isFormSubmitting, + currentWorkspace, + notifications?.toasts, + workspaceClient, + isPermissionEnabled, + ] ); if (!workspaces || !application || !http || !savedObjects || !currentWorkspaceFormData) {