(core) Implement checkbox for SchemaEdit permission in Access Rules UI.

Summary:
- Introduces a fictitious "*SPECIAL:SchemaEdit" resource in UI only.
- Hides "S" bit for the default rule section.
- Shows a checkbox UI similar to other checkboxes, with an additional
  dismissable warning.

Test Plan: Added a browser test

Reviewers: paulfitz, georgegevoian

Reviewed By: paulfitz, georgegevoian

Differential Revision: https://phab.getgrist.com/D3765
This commit is contained in:
Dmitry S
2023-01-18 10:36:11 -05:00
parent 18d016c745
commit 45c7602f49
4 changed files with 257 additions and 46 deletions

View File

@@ -190,3 +190,25 @@ export function summarizePermissions(perms: MixedPermissionValue[]): MixedPermis
const perm = perms[0];
return perms.some(p => p !== perm) ? 'mixed' : perm;
}
function isEmpty(permissions: PartialPermissionSet): boolean {
return Object.values(permissions).every(v => v === "");
}
/**
* Divide up a PartialPermissionSet into two: one containing only the 'schemaEdit' permission bit,
* and the other containing everything else. Empty parts will be returned as undefined, except
* when both are empty, in which case nonSchemaEdit will be returned as an empty permission set.
*/
export function splitSchemaEditPermissionSet(permissions: PartialPermissionSet):
{schemaEdit?: PartialPermissionSet, nonSchemaEdit?: PartialPermissionSet} {
const schemaEdit = {...emptyPermissionSet(), schemaEdit: permissions.schemaEdit};
const nonSchemaEdit: PartialPermissionSet = {...permissions, schemaEdit: ""};
return {
schemaEdit: !isEmpty(schemaEdit) ? schemaEdit : undefined,
nonSchemaEdit: !isEmpty(nonSchemaEdit) || isEmpty(schemaEdit) ? nonSchemaEdit : undefined,
};
}