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

[Workspace] fix: Fix workspace page hanging with none collaborators for non dashboard admin #9004

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/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))
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,6 +11,7 @@ import {
getNumberOfErrors,
isWorkspacePermissionSetting,
getPermissionModeName,
EMPTY_PERMISSIONS,
} from './utils';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionItemType, optionIdToWorkspacePermissionModesMap } from './constants';
Expand All @@ -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', () => {
Expand Down
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;
}
Comment on lines -107 to 116
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it has any impact when permission control is turned off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supposed it may not as this is a specific object for workspace object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when permission control is off, permission field will not initialized and add to kibana index, i am not sure it will cause any issue when try to save a object with empty permission, we can have a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the value of permission field will not be consistent between permission is on/off, right? So it seems updating client wrapper will be a better solution?

return permissionItems.reduce<SavedObjectPermissions>((previous, current) => {
current.modes.forEach((mode) => {
Expand Down
Loading