diff options
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index 2bc2bb3f8..3860decc9 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -34,12 +34,9 @@ import { List } from './List'; import { ObjectField } from './ObjectField'; import { PrefetchProxy, ProxyField } from './Proxy'; import { RefField } from './RefField'; -import { RichTextField } from './RichTextField'; import { SchemaHeaderField } from './SchemaHeaderField'; import { ComputedField } from './ScriptField'; import { ScriptCast, StrCast } from './Types'; -import { SharingManager } from '../client/util/SharingManager'; -import { PropertiesView } from '../client/views/PropertiesView'; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -86,7 +83,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number const fromServer = target[UpdatingFromServer]; const sameAuthor = fromServer || receiver.author === Doc.CurrentUserEmail; const writeToDoc = sameAuthor || effectiveAcl === AclEdit || effectiveAcl === AclAugment || effectiveAcl === AclAdmin || writeMode !== DocServer.WriteMode.LiveReadonly; - const writeToServer = (sameAuthor || effectiveAcl === AclEdit || effectiveAcl === AclAugment || effectiveAcl === AclAdmin ) && !DocServer.Control.isReadOnly(); + const writeToServer = (sameAuthor || effectiveAcl === AclEdit || effectiveAcl === AclAugment || effectiveAcl === AclAdmin) && !DocServer.Control.isReadOnly(); if (writeToDoc) { if (value === undefined) { @@ -187,7 +184,7 @@ 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) + target = Doc.GetProto(target); 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) @@ -212,21 +209,21 @@ export function SetCachedGroups(groups: string[]) { function getEffectiveAcl(target: any, user?: string): symbol { const targetAcls = target[AclSym]; if (targetAcls?.['acl-Me'] === AclAdmin || GetCachedGroupByName(SharingPermissions.Admin)) return AclAdmin; - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)]){ - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Admin){ - return AclAdmin + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)]) { + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Admin) { + return AclAdmin; } - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Edit){ - return AclEdit + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Edit) { + return AclEdit; } - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Augment){ - return AclAugment + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.Augment) { + return AclAugment; } - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.View){ - return AclReadonly + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.View) { + return AclReadonly; } - if (target['acl-'+normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.None){ - return AclPrivate + if (target['acl-' + normalizeEmail(Doc.CurrentUserEmail)] == SharingPermissions.None) { + return AclPrivate; } } 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 @@ -247,21 +244,19 @@ function getEffectiveAcl(target: any, user?: string): symbol { //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.__fields?.author || target.author; // target may be a Doc of Proxy, so check __fields.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)] + let acl = AclPrivate; + if (user) { + acl = target['acl-' + user]; + } else { + acl = target['acl-' + normalizeEmail(Doc.CurrentUserEmail)]; } - console.log(target['acl-'+normalizeEmail(Doc.CurrentUserEmail)]) + console.log(target['acl-' + normalizeEmail(Doc.CurrentUserEmail)]); return DocServer?.Control?.isReadOnly?.() && HierarchyMapping.get(acl)!.level < aclLevel.editable ? AclEdit : acl; } /** @@ -278,11 +273,10 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc if ((target._viewType === CollectionViewType.Docking && visited.length > 1) || Doc.GetProto(visited[0]) !== Doc.GetProto(target)) { target[key] = acl; - Doc.GetProto(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...???) updateCachedAcls(target); - } return; } @@ -331,7 +325,7 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean { let prop = in_prop; const effectiveAcl = in_prop === 'constructor' || typeof in_prop === 'symbol' ? AclAdmin : getPropAcl(target, prop); - if (effectiveAcl !== AclEdit && effectiveAcl !== AclAugment && effectiveAcl !== AclAdmin ) return true; + if (effectiveAcl !== AclEdit && effectiveAcl !== AclAugment && 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; @@ -406,7 +400,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any diff?.op === '$addToSet' ? { $addToSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List<Doc>(diff.items)) } } : diff?.op === '$remFromSet' - ? { $remFromSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List<Doc>(diff.items)), hint : diff.hint } } + ? { $remFromSet: { ['fields.' + prop]: SerializationHelper.Serialize(new List<Doc>(diff.items)), hint: diff.hint } } : { $set: { ['fields.' + prop]: SerializationHelper.Serialize(value) } }; !op.$set && ((op as any).length = diff.length); const prevValue = ObjectField.MakeCopy(lastValue as List<any>); |