diff options
author | Geireann Lindfield Roberts <60007097+geireann@users.noreply.github.com> | 2020-09-21 04:34:22 +0800 |
---|---|---|
committer | Geireann Lindfield Roberts <60007097+geireann@users.noreply.github.com> | 2020-09-21 04:34:22 +0800 |
commit | 0d28500e1155355f5efa8d602b862e6156282068 (patch) | |
tree | c1b6efe684e4cdfe10a5c333874a74663d15d226 /src/fields/util.ts | |
parent | 5e488f1d8ae46bc6001b898eade8c8f7ae21129e (diff) | |
parent | b9735a34252459ee7f09bb58a49cc3da7a652ab7 (diff) |
Merge branch 'presentation_v1' of https://github.com/browngraphicslab/Dash-Web into presentation_v1
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index 82525f92b..9db79ced1 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -111,7 +111,7 @@ export function makeEditable() { _setter = _setterImpl; } var _overrideAcl = false; -export function OVERRIDE_ACL(val: boolean) { +export function OVERRIDE_acl(val: boolean) { _overrideAcl = val; } @@ -168,7 +168,7 @@ export function GetEffectiveAcl(target: any, in_prop?: string | symbol | number, if (currentUserGroups.includes("Admin")) return AclAdmin; - // if the ACL is being overriden or the property being modified is one of the playground fields (which can be freely modified) + // if the acl is being overriden or the property being modified is one of the playground fields (which can be freely modified) if (_overrideAcl || (in_prop && DocServer.PlaygroundFields?.includes(in_prop.toString()))) return AclEdit; let effectiveAcl = AclPrivate; @@ -198,13 +198,16 @@ export function GetEffectiveAcl(target: any, in_prop?: string | symbol | number, } /** * Recursively distributes the access right for a user across the children of a document and its annotations. - * @param key the key storing the access right (e.g. ACL-groupname) + * @param key the key storing the access right (e.g. acl-groupname) * @param acl the access right being stored (e.g. "Can Edit") * @param target the document on which this access right is being set - * @param inheritingFromCollection whether the target is being assigned rights after being dragged into a collection (and so is inheriting the ACLs from the collection) - * inheritingFromCollection is not currently being used but could be used if ACL assignment defaults change + * @param inheritingFromCollection whether the target is being assigned rights after being dragged into a collection (and so is inheriting the acls from the collection) + * inheritingFromCollection is not currently being used but could be used if acl assignment defaults change */ -export function distributeAcls(key: string, acl: SharingPermissions, target: Doc, inheritingFromCollection?: boolean) { +export function distributeAcls(key: string, acl: SharingPermissions, target: Doc, inheritingFromCollection?: boolean, visited?: Doc[]) { + if (!visited) visited = [] as Doc[]; + if (visited.includes(target)) return; + visited.push(target); const HierarchyMapping = new Map<string, number>([ ["Not Shared", 0], @@ -229,32 +232,28 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc dataDocChanged = true; // maps over the aliases of the document - const aliases = DocListCast(dataDoc.aliases); - if (aliases.length) { - aliases.map(alias => { - alias !== target && distributeAcls(key, acl, alias, inheritingFromCollection); - }); - } + const links = DocListCast(dataDoc.links); + links.forEach(alias => distributeAcls(key, acl, alias, inheritingFromCollection, visited)); // maps over the children of the document DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc)]).map(d => { if (GetEffectiveAcl(d) === AclAdmin && (!inheritingFromCollection || !d[key] || HierarchyMapping.get(StrCast(d[key]))! > HierarchyMapping.get(acl)!)) { - distributeAcls(key, acl, d, inheritingFromCollection); + distributeAcls(key, acl, d, inheritingFromCollection, visited); } const data = d[DataSym]; if (data && GetEffectiveAcl(data) === AclAdmin && (!inheritingFromCollection || !data[key] || HierarchyMapping.get(StrCast(data[key]))! > HierarchyMapping.get(acl)!)) { - distributeAcls(key, acl, data, inheritingFromCollection); + distributeAcls(key, acl, data, inheritingFromCollection, visited); } }); // maps over the annotations of the document DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc) + "-annotations"]).map(d => { if (GetEffectiveAcl(d) === AclAdmin && (!inheritingFromCollection || !d[key] || HierarchyMapping.get(StrCast(d[key]))! > HierarchyMapping.get(acl)!)) { - distributeAcls(key, acl, d, inheritingFromCollection); + distributeAcls(key, acl, d, inheritingFromCollection, visited); } const data = d[DataSym]; if (data && GetEffectiveAcl(data) === AclAdmin && (!inheritingFromCollection || !data[key] || HierarchyMapping.get(StrCast(data[key]))! > HierarchyMapping.get(acl)!)) { - distributeAcls(key, acl, data, inheritingFromCollection); + distributeAcls(key, acl, data, inheritingFromCollection, visited); } }); } @@ -271,8 +270,8 @@ export function setter(target: any, in_prop: string | symbol | number, value: an if (effectiveAcl !== AclEdit && effectiveAcl !== AclAdmin) return true; // if you're trying to change an acl but don't have Admin access / you're trying to change it to something that isn't an acceptable acl, you can't - if (typeof prop === "string" && prop.startsWith("ACL") && (effectiveAcl !== AclAdmin || ![...Object.values(SharingPermissions), undefined].includes(value))) return true; - // if (typeof prop === "string" && prop.startsWith("ACL") && !["Can Edit", "Can Add", "Can View", "Not Shared", undefined].includes(value)) return true; + if (typeof prop === "string" && prop.startsWith("acl") && (effectiveAcl !== AclAdmin || ![...Object.values(SharingPermissions), undefined].includes(value))) return true; + // if (typeof prop === "string" && prop.startsWith("acl") && !["Can Edit", "Can Add", "Can View", "Not Shared", undefined].includes(value)) return true; if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && (prop.startsWith("_") || layoutProps.includes(prop))) { if (!prop.startsWith("_")) { |