Skip to content

Commit

Permalink
[Workspace] fix: Fix workspace page hanging with none collaborators f…
Browse files Browse the repository at this point in the history
…or non dashboard admin (#9004)

* fix: fix page hanging when none collaborators for non dashboard admin

Signed-off-by: tygao <[email protected]>

* add const type

Signed-off-by: tygao <[email protected]>

* Changeset file for PR #9004 created/updated

* Changeset file for PR #9004 created/updated

* update empty permissions when permission is disabled for workspace detail page

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: SuZhou-Joe <[email protected]>
(cherry picked from commit 40e61c7)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 2, 2025
1 parent 60067ba commit 62d929f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9004.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix workspace page hanging with none collaborators for non dashboard admin ([#9004](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9004))
15 changes: 13 additions & 2 deletions src/plugins/workspace/public/components/workspace_detail_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import {
getNumberOfErrors,
isWorkspacePermissionSetting,
getPermissionModeName,
EMPTY_PERMISSIONS,
} from './utils';
import { WorkspacePermissionItemType, optionIdToWorkspacePermissionModesMap } from './constants';
import { DataSourceConnectionType } from '../../../common/types';
import { WorkspaceFormErrorCode } from './types';
import { PermissionModeId, WorkspacePermissionMode } 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', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/workspace/public/components/workspace_form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const isValidFormTextInput = (input?: string) => {
return typeof input === 'string' && regex.test(input);
};

export const EMPTY_PERMISSIONS: SavedObjectPermissions = {
library_read: {},
library_write: {},
read: {},
write: {},
} as const;

export const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => {
let numberOfErrors = 0;
if (formErrors.name) {
Expand Down Expand Up @@ -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<SavedObjectPermissions>((previous, current) => {
current.modes.forEach((mode) => {
Expand Down

0 comments on commit 62d929f

Please sign in to comment.