Skip to content

Commit

Permalink
feat: show error when duplicate permissions for spefic user or group
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Oct 24, 2023
1 parent 9bc49f5 commit d203dd4
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ const getNumberOfErrors = (formErrors: WorkspaceFormErrors) => {
return numberOfErrors;
};

const isUserOrGroupPermissionSettingDuplicated = (
permissionSettings: Array<Partial<WorkspacePermissionSetting>>,
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' }];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d203dd4

Please sign in to comment.