aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Doc.ts19
-rw-r--r--src/fields/util.ts20
2 files changed, 18 insertions, 21 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 086b7777f..2452ab408 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -891,12 +891,11 @@ export namespace Doc {
export function GetSelectedTool(): InkTool { return StrCast(Doc.UserDoc().activeInkTool, InkTool.None) as InkTool; }
export function SetUserDoc(doc: Doc) { return (manager._user_doc = doc); }
- export function IsSearchMatch(doc: Doc) {
- return computedFn(function IsSearchMatch(doc: Doc) {
- return brushManager.SearchMatchDoc.has(doc) ? brushManager.SearchMatchDoc.get(doc) :
- brushManager.SearchMatchDoc.has(Doc.GetProto(doc)) ? brushManager.SearchMatchDoc.get(Doc.GetProto(doc)) : undefined;
- })(doc);
- }
+ const isSearchMatchCache = computedFn(function IsSearchMatch(doc: Doc) {
+ return brushManager.SearchMatchDoc.has(doc) ? brushManager.SearchMatchDoc.get(doc) :
+ brushManager.SearchMatchDoc.has(Doc.GetProto(doc)) ? brushManager.SearchMatchDoc.get(Doc.GetProto(doc)) : undefined;
+ });
+ export function IsSearchMatch(doc: Doc) { return isSearchMatchCache(doc); }
export function IsSearchMatchUnmemoized(doc: Doc) {
return brushManager.SearchMatchDoc.has(doc) ? brushManager.SearchMatchDoc.get(doc) :
brushManager.SearchMatchDoc.has(Doc.GetProto(doc)) ? brushManager.SearchMatchDoc.get(Doc.GetProto(doc)) : undefined;
@@ -918,11 +917,9 @@ export namespace Doc {
brushManager.SearchMatchDoc.clear();
}
- export function IsBrushed(doc: Doc) {
- return computedFn(function IsBrushed(doc: Doc) {
- return brushManager.BrushedDoc.has(doc) || brushManager.BrushedDoc.has(Doc.GetProto(doc));
- })(doc);
- }
+ const isBrushedCache = computedFn(function IsBrushed(doc: Doc) { return brushManager.BrushedDoc.has(doc) || brushManager.BrushedDoc.has(Doc.GetProto(doc)); });
+ export function IsBrushed(doc: Doc) { return isBrushedCache(doc); }
+
// don't bother memoizing (caching) the result if called from a non-reactive context. (plus this avoids a warning message)
export function IsBrushedDegreeUnmemoized(doc: Doc) {
if (!doc || GetEffectiveAcl(doc) === AclPrivate || GetEffectiveAcl(Doc.GetProto(doc)) === AclPrivate) return 0;
diff --git a/src/fields/util.ts b/src/fields/util.ts
index b68d961b1..5cd8df564 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -154,30 +154,30 @@ export enum SharingPermissions {
None = "Not Shared"
}
+// return acl from cache or cache the acl and return.
+const getEffectiveAclCache = computedFn(function (target: any, playgroundProp: boolean, user?: string) { return getEffectiveAcl(target, playgroundProp, user); }, true);
+
/**
* Calculates the effective access right to a document for the current user.
*/
export function GetEffectiveAcl(target: any, in_prop?: string | symbol | number, user?: string): symbol {
- return computedFn(function (target: any, in_prop?: string | symbol | number, user?: string) {
- return getEffectiveAcl(target, in_prop, user);
- }, true)(target, in_prop, user);
-}
-function getEffectiveAcl(target: any, in_prop?: string | symbol | number, user?: string): symbol {
if (!target) return AclPrivate;
+ if (in_prop === UpdatingFromServer) return AclAdmin; // requesting the UpdatingFromServer prop must always go through to keep the local DB consistent
+ const playgroundProp = in_prop && DocServer.PlaygroundFields?.includes(in_prop.toString()) ? true : false;
+ return getEffectiveAclCache(target, playgroundProp, user);
+}
- // all changes received fromt the server must be processed as Admin
- if (in_prop === UpdatingFromServer || target[UpdatingFromServer]) return AclAdmin;
-
+function getEffectiveAcl(target: any, playgroundProp: boolean, user?: string): symbol {
+ if (target[UpdatingFromServer]) return AclAdmin; // all changes received from the server must be processed as Admin
// if the current user is the author of the document / the current user is a member of the admin group
const userChecked = user || Doc.CurrentUserEmail;
if (userChecked === (target.__fields?.author || target.author)) return AclAdmin;
if (SnappingManager.GetCachedGroupByName("Admin")) return AclAdmin;
-
if (target[AclSym] && Object.keys(target[AclSym]).length) {
// 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;
+ if (_overrideAcl || playgroundProp) return AclEdit;
let effectiveAcl = AclPrivate;
const HierarchyMapping = new Map<symbol, number>([