diff options
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index 469e4d944..6c8758875 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -17,6 +17,7 @@ import { RefField } from './RefField'; import { SchemaHeaderField } from './SchemaHeaderField'; import { ComputedField } from './ScriptField'; import { ScriptCast, StrCast } from './Types'; +import { GroupManager } from '../client/util/GroupManager'; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -171,7 +172,15 @@ const getEffectiveAclCache = computedFn(function (target: any, user?: string) { * Calculates the effective access right to a document for the current user. */ export function GetEffectiveAcl(target: any, user?: string): symbol { - target = Doc.GetProto(target); + if (!target) return AclPrivate; + if (target[UpdatingFromServer]) return AclAdmin; + return getEffectiveAclCache(Doc.GetProto(target), user); // all changes received from the server must be processed as Admin. return this directly so that the acls aren't cached (UpdatingFromServer is not observable) +} + +/** + * Calculates the effective access layout right to a document for the current user. + */ +export function GetEffectiveLayoutAcl(target: any, user?: string): symbol { if (!target) return AclPrivate; if (target[UpdatingFromServer]) return AclAdmin; return getEffectiveAclCache(target, user); // all changes received from the server must be processed as Admin. return this directly so that the acls aren't cached (UpdatingFromServer is not observable) @@ -195,7 +204,6 @@ export function SetCachedGroups(groups: string[]) { } function getEffectiveAcl(target: any, user?: string): symbol { const targetAcls = target[DocAcl]; - console.log(target.title, targetAcls) if (targetAcls?.['acl-Me'] === AclAdmin || GetCachedGroupByName('Admin')) return AclAdmin; const userChecked = user || Doc.CurrentUserEmail; // if the current user is the author of the document / the current user is a member of the admin group @@ -205,31 +213,20 @@ function getEffectiveAcl(target: any, user?: string): symbol { // there are issues with storing fields with . in the name, so they are replaced with _ during creation // as a result we need to restore them again during this comparison. const entity = denormalizeEmail(key.substring(4)); // an individual or a group - if (HierarchyMapping.get(value as symbol)!.level > HierarchyMapping.get(effectiveAcl)!.level) { - if (GetCachedGroupByName(entity) || userChecked === entity || entity === 'Me') { + if (GetCachedGroupByName(entity) || userChecked === entity || entity === 'Me') { + if (HierarchyMapping.get(value as symbol)!.level > HierarchyMapping.get(effectiveAcl)!.level) { effectiveAcl = value as symbol; } } + console.log(targetAcls) } - // if there's an overriding acl set through the properties panel or sharing menu, that's what's returned if the user isn't an admin of the document - //const override = targetAcls['acl-Override']; - // if (override !== AclUnset && override !== undefined) effectiveAcl = override; - return DocServer?.Control?.isReadOnly?.() && HierarchyMapping.get(effectiveAcl)!.level < aclLevel.editable ? AclEdit : effectiveAcl; } // authored documents are private until an ACL is set. const targetAuthor = target.__fieldTuples?.author || target.author; // target may be a Doc of Proxy, so check __fieldTuples.author and .author if (targetAuthor && targetAuthor !== userChecked) return AclPrivate; return AclAdmin; - let acl = AclPrivate; - if (user) { - acl = target['acl-' + user]; - } else { - acl = target['acl-' + normalizeEmail(Doc.CurrentUserEmail)]; - } - console.log(target['acl-' + normalizeEmail(Doc.CurrentUserEmail)]); - return DocServer?.Control?.isReadOnly?.() && HierarchyMapping.get(acl)!.level < aclLevel.editable ? AclEdit : acl; } /** * Recursively distributes the access right for a user across the children of a document and its annotations. @@ -240,11 +237,10 @@ function getEffectiveAcl(target: any, user?: string): symbol { * 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, visited?: Doc[], isDashboard?: boolean) { + console.log(key,acl,target.title) if (!visited) visited = [] as Doc[]; if (!target || visited.includes(target)) return; - if ((target._type_collection === CollectionViewType.Docking && visited.length > 1) || Doc.GetProto(visited[0]) !== Doc.GetProto(target)) { - target[key] = acl; Doc.GetProto(target)[key] = acl; if (target !== Doc.GetProto(target)) { //apparently we can't call updateCachedAcls twice (once for the main dashboard, and again for the nested dashboard...???) |