aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DocComponent.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/DocComponent.tsx')
-rw-r--r--src/client/views/DocComponent.tsx61
1 files changed, 20 insertions, 41 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 1d0feec74..44af51341 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -1,18 +1,16 @@
import { action, computed, observable } from 'mobx';
import { DateField } from '../../fields/DateField';
-import { DocListCast, Opt, Doc, ReverseHierarchyMap, HierarchyMapping } from '../../fields/Doc';
+import { Doc, DocListCast, HierarchyMapping, Opt, ReverseHierarchyMap } from '../../fields/Doc';
import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocAcl, DocData } from '../../fields/DocSymbols';
import { List } from '../../fields/List';
-import { Cast, DocCast, ScriptCast, StrCast } from '../../fields/Types';
-import { denormalizeEmail, distributeAcls, GetEffectiveAcl, inheritParentAcls, normalizeEmail, SharingPermissions } from '../../fields/util';
+import { Cast, StrCast } from '../../fields/Types';
+import { distributeAcls, GetEffectiveAcl, inheritParentAcls, SharingPermissions } from '../../fields/util';
import { returnFalse } from '../../Utils';
import { DocUtils } from '../documents/Documents';
import { DocumentType } from '../documents/DocumentTypes';
import { InteractionUtils } from '../util/InteractionUtils';
-import { UndoManager } from '../util/UndoManager';
import { DocumentView } from './nodes/DocumentView';
import { Touchable } from './Touchable';
-import { SharingManager } from '../util/SharingManager';
/// DocComponent returns a generic React base class used by views that don't have 'fieldKey' props (e.g.,CollectionFreeFormDocumentView, DocumentView)
export interface DocComponentProps {
@@ -184,7 +182,7 @@ export function ViewBoxAnnotatableComponent<P extends ViewBoxAnnotatableProps>()
if (this.props.filterAddDocument?.(docs) === false || docs.find(doc => Doc.AreProtosEqual(doc, this.props.Document) && Doc.LayoutField(doc) === Doc.LayoutField(this.props.Document))) {
return false;
}
- const targetDataDoc = this.props.Document[DocData];
+ const targetDataDoc = this.rootDoc[DocData];
const effectiveAcl = GetEffectiveAcl(targetDataDoc);
if (effectiveAcl === AclPrivate || effectiveAcl === AclReadonly) {
@@ -194,52 +192,33 @@ export function ViewBoxAnnotatableComponent<P extends ViewBoxAnnotatableProps>()
if (added.length) {
const aclKeys = Object.keys(Doc.GetProto(this.props.Document)[DocAcl] ?? {});
- aclKeys.forEach(key =>
- added.forEach(d => {
- if (key != 'acl-Me') {
- const permissionString = StrCast(Doc.GetProto(this.props.Document)[key]);
- const permissionSymbol = ReverseHierarchyMap.get(permissionString)!.acl;
- const permission = HierarchyMapping.get(permissionSymbol)!.name;
- distributeAcls(key, permission, Doc.GetProto(d));
- }
- })
- );
+ GetEffectiveAcl(this.rootDoc) === AclAdmin &&
+ aclKeys.forEach(key =>
+ added.forEach(d => {
+ if (key != 'acl-Me') {
+ const permissionString = StrCast(Doc.GetProto(this.props.Document)[key]);
+ const permissionSymbol = ReverseHierarchyMap.get(permissionString)?.acl;
+ const permission = permissionSymbol && HierarchyMapping.get(permissionSymbol)?.name;
+ distributeAcls(key, permission ?? SharingPermissions.Augment, Doc.GetProto(d));
+ }
+ })
+ );
if (effectiveAcl === AclAugment) {
added.map(doc => {
- Doc.SetContainer(doc, this.props.Document);
- if (annotationKey ?? this._annotationKeySuffix()) Doc.GetProto(doc).annotationOn = this.props.Document;
+ if (annotationKey ?? this._annotationKeySuffix()) Doc.GetProto(doc).annotationOn = this.rootDoc;
Doc.AddDocToList(targetDataDoc, annotationKey ?? this.annotationKey, doc);
- const parent = DocCast(doc.embedContainer);
- doc.embedContainer && inheritParentAcls(parent, doc);
- for (const key of Object.keys(parent)) {
- const symbol = ReverseHierarchyMap.get(StrCast(parent[key]));
- if (symbol && key.startsWith('acl')) {
- const sharePermission = HierarchyMapping.get(symbol.acl!)!.name;
- const user = SharingManager.Instance?.users.filter(({ user: { email } }) => normalizeEmail(email) == key.slice(4))[0];
- if (user && sharePermission !== SharingPermissions.None) return Doc.AddDocToList(user.sharingDoc, 'data', doc);
- }
- }
+ Doc.SetContainer(doc, targetDataDoc);
+ inheritParentAcls(targetDataDoc, doc);
});
} else {
added
.filter(doc => [AclAdmin, AclEdit].includes(GetEffectiveAcl(doc)))
.map(doc => {
- // only make a pushpin if we have acl's to edit the document
- //DocUtils.LeavePushpin(doc);
doc._dragOnlyWithinContainer = undefined;
- Doc.SetContainer(doc, this.props.Document);
if (annotationKey ?? this._annotationKeySuffix()) Doc.GetProto(doc).annotationOn = this.rootDoc;
- const parent = DocCast(doc.embedContainer);
- doc.embedContainer && inheritParentAcls(parent, doc);
- for (const key of Object.keys(Doc.GetProto(parent))) {
- const symbol = ReverseHierarchyMap.get(StrCast(parent[key]));
- if (symbol && key.startsWith('acl')) {
- const sharePermission = HierarchyMapping.get(symbol.acl!)!.name;
- const user = SharingManager.Instance?.users.filter(({ user: { email } }) => normalizeEmail(email) == key.slice(4))[0];
- if (user && sharePermission !== SharingPermissions.None) return Doc.AddDocToList(user.sharingDoc, 'data', doc);
- }
- }
+ Doc.SetContainer(doc, this.rootDoc);
+ inheritParentAcls(targetDataDoc, doc);
});
const annoDocs = targetDataDoc[annotationKey ?? this.annotationKey] as List<Doc>;