diff options
author | bobzel <zzzman@gmail.com> | 2023-07-11 15:32:08 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2023-07-11 15:32:08 -0400 |
commit | 06cfe3cbba127d865e788b00561f8a591af1bd81 (patch) | |
tree | 2aeb0132d33e04c90483a46a3482ab3d8c4744d8 /src/fields/util.ts | |
parent | 8a852df1c918d8e31ba0b540798895fcd420cca7 (diff) |
more fixes to simplify sharing
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index 034229319..e89cb1fb1 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -131,17 +131,19 @@ export function denormalizeEmail(email: string) { /** * Copies parent's acl fields to the child */ -export function inheritParentAcls(parent: Doc, child: Doc) { +export function inheritParentAcls(parent: Doc, child: Doc, layoutOnly: boolean) { if (GetEffectiveAcl(parent) !== AclAdmin) return; - for (const key of Object.keys(parent)) { - // if the default acl mode is private, then don't inherit the acl-Public permission, but set it to private. - // const permission: string = key === 'acl-Public' && Doc.defaultAclPrivate ? AclPrivate : parent[key]; - const symbol = ReverseHierarchyMap.get(StrCast(parent[key])); - if (symbol) { - const sharePermission = HierarchyMapping.get(symbol.acl!)!.name; - key.startsWith('acl') && distributeAcls(key, sharePermission, child); - } - } + Object.keys(parent) + .filter(key => key.startsWith('acl')) + .forEach(key => { + // if the default acl mode is private, then don't inherit the acl-guest permission, but set it to private. + // const permission: string = key === 'acl-guest' && Doc.defaultAclPrivate ? AclPrivate : parent[key]; + const parAcl = ReverseHierarchyMap.get(StrCast(parent[key]))?.acl; + if (parAcl) { + const sharePermission = HierarchyMapping.get(parAcl)?.name; + sharePermission && distributeAcls(key, sharePermission, child, undefined, false, layoutOnly); + } + }); } /** @@ -160,7 +162,6 @@ export function inheritParentAcls(parent: Doc, child: Doc) { * Unset: Remove a sharing permission (eg., used ) */ export enum SharingPermissions { - Unset = 'None', Admin = 'Admin', Edit = 'Edit', Augment = 'Augment', @@ -233,7 +234,7 @@ function getEffectiveAcl(target: any, user?: string): symbol { * @param allowUpgrade whether permissions can be made less restrictive * inheritingFromCollection is not currently being used but could be used if acl assignment defaults change */ -export function distributeAcls(key: string, acl: SharingPermissions, target: Doc, visited?: Doc[], allowUpgrade?: boolean) { +export function distributeAcls(key: string, acl: SharingPermissions, target: Doc, visited?: Doc[], allowUpgrade?: boolean, layoutOnly = false) { const selfKey = `acl-${Doc.CurrentUserEmailNormalized}`; if (!visited) visited = [] as Doc[]; if (!target || visited.includes(target) || key === selfKey) return; @@ -243,19 +244,19 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc const dataDoc = target[DocData]; const curVal = ReverseHierarchyMap.get(StrCast(dataDoc[key]))?.level ?? 0; const aclVal = ReverseHierarchyMap.get(acl)?.level ?? 0; - if (dataDoc && (allowUpgrade !== false|| !dataDoc[key] || curVal > aclVal)) { + if (!layoutOnly && dataDoc && (allowUpgrade !== false || !dataDoc[key] || curVal > aclVal)) { // propagate ACLs to links, children, and annotations - LinkManager.Links(dataDoc).forEach(link => distributeAcls(key, acl, link, visited, allowUpgrade? true: false)); + LinkManager.Links(dataDoc).forEach(link => distributeAcls(key, acl, link, visited, allowUpgrade ? true : false)); DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc)]).forEach(d => { - distributeAcls(key, acl, d, visited, allowUpgrade ? true: false); - d !== d[DocData] && distributeAcls(key, acl, d[DocData], visited, allowUpgrade ? true: false); + distributeAcls(key, acl, d, visited, allowUpgrade ? true : false); + d !== d[DocData] && distributeAcls(key, acl, d[DocData], visited, allowUpgrade ? true : false); }); DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc) + '_annotations']).forEach(d => { - distributeAcls(key, acl, d, visited, allowUpgrade? true: false); - d !== d[DocData] && distributeAcls(key, acl, d[DocData], visited, allowUpgrade? true: false); + distributeAcls(key, acl, d, visited, allowUpgrade ? true : false); + d !== d[DocData] && distributeAcls(key, acl, d[DocData], visited, allowUpgrade ? true : false); }); if (GetEffectiveAcl(dataDoc) === AclAdmin) { @@ -266,7 +267,7 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc let layoutDocChanged = false; // determines whether fetchProto should be called or not (i.e. is there a change that should be reflected in target[AclSym]) // if it is inheriting from a collection, it only inherits if A) allowUpgrade is set B) the key doesn't already exist or c) the right being inherited is more restrictive - if (GetEffectiveAcl(target) === AclAdmin && (allowUpgrade || !target[key] || ReverseHierarchyMap.get(StrCast(target[key]))!.level > ReverseHierarchyMap.get(acl)!.level)) { + if (GetEffectiveAcl(target) === AclAdmin && (allowUpgrade || !Doc.GetT(target, key, 'boolean', true) || ReverseHierarchyMap.get(StrCast(target[key]))!.level > aclVal)) { target[key] = acl; layoutDocChanged = true; } |