diff options
-rw-r--r-- | src/client/documents/Documents.ts | 1 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 18 | ||||
-rw-r--r-- | src/fields/Doc.ts | 25 |
3 files changed, 31 insertions, 13 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index f7e19eecd..1a1d5c59e 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -514,6 +514,7 @@ export namespace Docs { const dataDoc = MakeDataDelegate(proto, protoProps, data, fieldKey); const viewDoc = Doc.MakeDelegate(dataDoc, delegId); + viewDoc.author = Doc.CurrentUserEmail; viewDoc.type !== DocumentType.LINK && DocUtils.MakeLinkToActiveAudio(viewDoc); return Doc.assign(viewDoc, delegateProps, true); diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index e245e045c..d132f0b3b 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -44,6 +44,7 @@ import "./DocumentView.scss"; import { LinkAnchorBox } from './LinkAnchorBox'; import { RadialMenu } from './RadialMenu'; import React = require("react"); +import { undo } from 'prosemirror-history'; library.add(fa.faEdit, fa.faTrash, fa.faShare, fa.faDownload, fa.faExpandArrowsAlt, fa.faCompressArrowsAlt, fa.faLayerGroup, fa.faExternalLinkAlt, fa.faAlignCenter, fa.faCaretSquareRight, fa.faSquare, fa.faConciergeBell, fa.faWindowRestore, fa.faFolder, fa.faMapPin, fa.faLink, fa.faFingerprint, fa.faCrosshairs, fa.faDesktop, fa.faUnlock, fa.faLock, fa.faLaptopCode, fa.faMale, @@ -682,6 +683,17 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu this.Document.lockedPosition = this.Document.lockedPosition ? undefined : true; } + @undoBatch + @action + setAcl = (acl: "readOnly" | "addOnly" | "ownerOnly") => { + this.layoutDoc.ACL = this.dataDoc.ACL = acl; + DocListCast(this.dataDoc[Doc.LayoutFieldKey(this.dataDoc)]).map(d => { + if (d.author === Doc.CurrentUserEmail) d.ACL = acl; + const data = d[DataSym]; + if (data && data.author === Doc.CurrentUserEmail) data.ACL = acl; + }); + } + @action onContextMenu = async (e: React.MouseEvent | Touch): Promise<void> => { // the touch onContextMenu is button 0, the pointer onContextMenu is button 2 @@ -742,9 +754,9 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu const more = cm.findByDescription("More..."); const moreItems: ContextMenuProps[] = more && "subitems" in more ? more.subitems : []; - moreItems.push({ description: "Make Add Only", event: () => this.dataDoc.ACL = this.layoutDoc.ACL = "addOnly", icon: "concierge-bell" }); - moreItems.push({ description: "Make Read Only", event: () => this.dataDoc.ACL = this.layoutDoc.ACL = "readOnly", icon: "concierge-bell" }); - moreItems.push({ description: "Make Private", event: () => this.dataDoc.ACL = this.layoutDoc.ACL = "noAccess", icon: "concierge-bell" }); + moreItems.push({ description: "Make Add Only", event: () => this.setAcl("addOnly"), icon: "concierge-bell" }); + moreItems.push({ description: "Make Read Only", event: () => this.setAcl("readOnly"), icon: "concierge-bell" }); + moreItems.push({ description: "Make Private", event: () => this.setAcl("ownerOnly"), icon: "concierge-bell" }); moreItems.push({ description: "Make View of Metadata Field", event: () => Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.DataDoc), icon: "concierge-bell" }); moreItems.push({ description: `${this.Document._chromeStatus !== "disabled" ? "Hide" : "Show"} Chrome`, event: () => this.Document._chromeStatus = (this.Document._chromeStatus !== "disabled" ? "disabled" : "enabled"), icon: "project-diagram" }); moreItems.push({ description: this.Document.lockedPosition ? "Unlock Position" : "Lock Position", event: this.toggleLockPosition, icon: BoolCast(this.Document.lockedPosition) ? "unlock" : "lock" }); diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 6891bf652..e46acd16d 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -94,7 +94,7 @@ export const HeightSym = Symbol("Height"); export const DataSym = Symbol("Data"); export const LayoutSym = Symbol("Layout"); export const AclSym = Symbol("Acl"); -export const AclPrivate = Symbol("AclNoAccess"); +export const AclPrivate = Symbol("AclOwnerOnly"); export const AclReadonly = Symbol("AclReadOnly"); export const AclAddonly = Symbol("AclAddonly"); export const UpdatingFromServer = Symbol("UpdatingFromServer"); @@ -103,13 +103,17 @@ const CachedUpdates = Symbol("Cached updates"); function fetchProto(doc: Doc) { if (doc.author !== Doc.CurrentUserEmail) { - if (doc.ACL === "noAccess") { - doc[AclSym] = AclPrivate; - return undefined; - } else if (doc.ACL === "readOnly") { - doc[AclSym] = AclReadonly; - } else if (doc.ACL === "addOnly") { - doc[AclSym] = AclAddonly; + const acl = Doc.Get(doc, "ACL", true); + switch (acl) { + case "ownerOnly": + doc[AclSym] = AclPrivate; + return undefined; + case "readOnly": + doc[AclSym] = AclReadonly; + break; + case "addOnly": + doc[AclSym] = AclAddonly; + break; } } @@ -117,7 +121,7 @@ function fetchProto(doc: Doc) { if (proto instanceof Promise) { proto.then(proto => { if (proto.author !== Doc.CurrentUserEmail) { - if (proto.ACL === "noAccess") { + if (proto.ACL === "ownerOnly") { proto[AclSym] = doc[AclSym] = AclPrivate; return undefined; } else if (proto.ACL === "readOnly") { @@ -484,6 +488,7 @@ export namespace Doc { } alias.aliasOf = doc; alias.title = ComputedField.MakeFunction(`renameAlias(this, ${Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1})`); + alias.author = Doc.CurrentUserEmail; return alias; } @@ -614,7 +619,7 @@ export namespace Doc { } } }); - + copy["author"] = Doc.CurrentUserEmail; return copy; } |