diff options
author | bobzel <zzzman@gmail.com> | 2020-10-12 17:22:26 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2020-10-12 17:22:26 -0400 |
commit | 8ebf3cb0ac7a023aa47a5264d74c3edaebf28b1b (patch) | |
tree | 9e5f51fc81de6b3254c7ce398cd261f93114e296 /src/fields/Doc.ts | |
parent | 04bbff759710d58fa97ce2f0d685ec59b6beb60e (diff) |
updated getEffectiveAcl to be a computedFn. got rid of OverrideAcl in favor of just using UpdatingFromServer
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r-- | src/fields/Doc.ts | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 2452ab408..cea09b9c5 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -102,22 +102,28 @@ const AclMap = new Map<string, symbol>([ [SharingPermissions.Admin, AclAdmin] ]); -export function fetchProto(doc: Doc) { +// caches the document access permissions for the current user. +// this recursively updates all protos as well. +export function updateCachedAcls(doc: Doc) { if (!doc) return; const permissions: { [key: string]: symbol } = {}; + doc[UpdatingFromServer] = true; Object.keys(doc).filter(key => key.startsWith("acl") && (permissions[key] = AclMap.get(StrCast(doc[key]))!)); + doc[UpdatingFromServer] = false; - if (Object.keys(permissions).length) doc[AclSym] = permissions; + if (Object.keys(permissions).length) { + doc[AclSym] = permissions; + } if (doc.proto instanceof Promise) { - doc.proto.then(fetchProto); + doc.proto.then(updateCachedAcls); return doc.proto; } } @scriptingGlobal -@Deserializable("Doc", fetchProto).withFields(["id"]) +@Deserializable("Doc", updateCachedAcls).withFields(["id"]) export class Doc extends RefField { constructor(id?: FieldId, forceSave?: boolean) { super(id); @@ -233,17 +239,15 @@ export class Doc extends RefField { const prev = GetEffectiveAcl(this); this[UpdatingFromServer] = true; this[fKey] = value; + this[UpdatingFromServer] = false; if (fKey.startsWith("acl")) { - fetchProto(this); + updateCachedAcls(this); } - this[UpdatingFromServer] = false; if (prev === AclPrivate && GetEffectiveAcl(this) !== AclPrivate) { DocServer.GetRefField(this[Id], true); } // if (prev !== AclPrivate && GetEffectiveAcl(this) === AclPrivate) { - // this[UpdatingFromServer] = true; // this[FieldsSym](true); - // this[UpdatingFromServer] = false; // } }; if (sameAuthor || fKey.startsWith("acl") || DocServer.getFieldWriteMode(fKey) !== DocServer.WriteMode.Playground) { |