aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-07-13 11:46:35 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-07-13 11:46:35 -0400
commitdb15b1d27a639af7a65f72dd5e4b6ea298412315 (patch)
tree305996a77e228c82e8866ef543377aaaf858bdf6 /src
parentc5eee7d838acb6991d1e37e0160cf77f5fc6aa34 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/client/util/SharingManager.tsx3
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx2
-rw-r--r--src/fields/Doc.ts12
-rw-r--r--src/fields/util.ts8
4 files changed, 13 insertions, 12 deletions
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index af68edab6..050ff0c4e 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -146,6 +146,7 @@ export default class SharingManager extends React.Component<{}> {
const ACL = `ACL-${StrCast(group.groupName)}`;
target[ACL] = permission;
+ Doc.GetProto(target)[ACL] = permission;
group.docsShared ? DocListCastAsync(group.docsShared).then(resolved => Doc.IndexOf(target, resolved!) === -1 && (group.docsShared as List<Doc>).push(target)) : group.docsShared = new List<Doc>([target]);
// group.docsShared ? Doc.IndexOf(target, DocListCast(group.docsShared)) === -1 && (group.docsShared as List<Doc>).push(target) : group.docsShared = new List<Doc>([target]);
@@ -215,7 +216,7 @@ export default class SharingManager extends React.Component<{}> {
// const permissions: { [key: string]: number } = target[ACL] ? JSON.parse(StrCast(target[ACL])) : {};
target[ACL] = permission;
-
+ Doc.GetProto(target)[ACL] = permission;
if (permission !== SharingPermissions.None) {
console.log(target);
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index 0af941182..01fbcb020 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -237,7 +237,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
this._applyingChange = true;
(curText !== Cast(this.dataDoc[this.fieldKey], RichTextField)?.Text) && (this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now())));
if ((!curTemp && !curProto) || curText || curLayout?.Data.includes("dash")) { // if no template, or there's text that didn't come from the layout template, write it to the document. (if this is driven by a template, then this overwrites the template text which is intended)
- if (json !== curLayout?.Data) {
+ if (json.replace(/"selection":.*/, "") !== curLayout?.Data.replace(/"selection":.*/, "")) {
!curText && tx.storedMarks?.map(m => m.type.name === "pFontSize" && (Doc.UserDoc().fontSize = this.layoutDoc._fontSize = m.attrs.fontSize));
!curText && tx.storedMarks?.map(m => m.type.name === "pFontFamily" && (Doc.UserDoc().fontFamily = this.layoutDoc._fontFamily = m.attrs.fontFamily));
this.dataDoc[this.props.fieldKey] = new RichTextField(json, curText);
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<string, symbol>([
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<symbol, number>([
[AclPrivate, 0],