From db15b1d27a639af7a65f72dd5e4b6ea298412315 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Mon, 13 Jul 2020 11:46:35 -0400 Subject: fixed issues with ACLs and writing to playground fields when you have Edit permission. Also fixed text editing by fixing fetchProto to use untracked references to fields --- src/fields/Doc.ts | 12 +++++------- src/fields/util.ts | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/fields') diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index e8dca5fb6..8ab4735a7 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -1,4 +1,4 @@ -import { action, computed, observable, ObservableMap, runInAction } from "mobx"; +import { action, computed, observable, ObservableMap, runInAction, untracked } from "mobx"; import { computedFn } from "mobx-utils"; import { alias, map, serializable } from "serializr"; import { DocServer } from "../client/DocServer"; @@ -110,15 +110,13 @@ const AclMap = new Map([ export function fetchProto(doc: Doc) { if (doc.author !== Doc.CurrentUserEmail) { // storing acls for groups needs to be extended here - AclSym should store a datastructure that stores information about permissions + untracked(() => { + const permissions: { [key: string]: symbol } = {}; - const permissions: { [key: string]: symbol } = {}; + Object.keys(doc).filter(key => key.startsWith("ACL")).forEach(key => permissions[key] = AclMap.get(StrCast(doc[key]))!); - Object.keys(doc).forEach(key => { - if (key.startsWith("ACL")) permissions[key] = AclMap.get(StrCast(doc[key]))!; + if (Object.keys(permissions).length) doc[AclSym] = permissions; }); - - - if (Object.keys(permissions).length) doc[AclSym] = permissions; } if (doc.proto instanceof Promise) { diff --git a/src/fields/util.ts b/src/fields/util.ts index ebfc3933a..be7736413 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -70,8 +70,8 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number const writeMode = DocServer.getFieldWriteMode(prop as string); const fromServer = target[UpdatingFromServer]; const sameAuthor = fromServer || (receiver.author === Doc.CurrentUserEmail); - const writeToDoc = sameAuthor || (writeMode !== DocServer.WriteMode.LiveReadonly); - const writeToServer = (sameAuthor || (writeMode === DocServer.WriteMode.Default)) && !playgroundMode; + const writeToDoc = sameAuthor || GetEffectiveAcl(target) === AclEdit || (writeMode !== DocServer.WriteMode.LiveReadonly); + const writeToServer = (sameAuthor || GetEffectiveAcl(target) === AclEdit || writeMode === DocServer.WriteMode.Default) && !playgroundMode; if (writeToDoc) { if (value === undefined) { @@ -91,8 +91,9 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number redo: () => receiver[prop] = value, undo: () => receiver[prop] = curValue }); + return true; } - return true; + return false; }); let _setter: (target: any, prop: string | symbol | number, value: any, receiver: any) => boolean = _setterImpl; @@ -126,6 +127,7 @@ export function setGroups(groups: string[]) { } export function GetEffectiveAcl(target: any, in_prop?: string | symbol | number): symbol { + if (in_prop === UpdatingFromServer || target[UpdatingFromServer]) return AclEdit; const HierarchyMapping = new Map([ [AclPrivate, 0], -- cgit v1.2.3-70-g09d2