From ab9465ec443811d7bc7884bc90dc593d57107c81 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Tue, 24 Oct 2023 17:17:41 +0800 Subject: [PATCH] feat: show error when duplicate permissions for spefic user or group Signed-off-by: Lin Wang --- .../workspace_creator/workspace_form.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/plugins/workspace/public/components/workspace_creator/workspace_form.tsx b/src/plugins/workspace/public/components/workspace_creator/workspace_form.tsx index d2a540db46ba..b2ff40855a9d 100644 --- a/src/plugins/workspace/public/components/workspace_creator/workspace_form.tsx +++ b/src/plugins/workspace/public/components/workspace_creator/workspace_form.tsx @@ -130,6 +130,20 @@ const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => { return numberOfErrors; }; +const isUserOrGroupPermissionSettingDuplicated = ( + permissionSettings: Array>, + permissionSettingToCheck: WorkspacePermissionSetting +) => + permissionSettings.some( + (permissionSetting) => + (permissionSettingToCheck.type === WorkspacePermissionItemType.User && + permissionSetting.type === WorkspacePermissionItemType.User && + permissionSettingToCheck.userId === permissionSetting.userId) || + (permissionSettingToCheck.type === WorkspacePermissionItemType.Group && + permissionSetting.type === WorkspacePermissionItemType.Group && + permissionSettingToCheck.group === permissionSetting.group) + ); + const workspaceHtmlIdGenerator = htmlIdGenerator(); const defaultVISThemeOptions = [{ value: 'categorical', text: 'Categorical' }]; @@ -377,6 +391,14 @@ export const WorkspaceForm = ({ for (let i = 0; i < formData.permissions.length; i++) { const permission = formData.permissions[i]; if (isValidWorkspacePermissionSetting(permission)) { + if ( + isUserOrGroupPermissionSettingDuplicated(formData.permissions.slice(0, i), permission) + ) { + permissionErrors[i] = i18n.translate('workspace.form.permission.invalidate.group', { + defaultMessage: 'Duplicate permission setting', + }); + continue; + } continue; } if (!permission.type) {