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.tsx47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index 70d208a0b..f3aa8451a 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -1,10 +1,10 @@
import { action, computed, observable } from 'mobx';
import { DateField } from '../../fields/DateField';
-import { DocListCast, Opt, Doc } from '../../fields/Doc';
+import { DocListCast, Opt, Doc, ReverseHierarchyMap, HierarchyMapping } from '../../fields/Doc';
import { AclAdmin, AclAugment, AclEdit, AclPrivate, AclReadonly, DocAcl, DocData } from '../../fields/DocSymbols';
import { List } from '../../fields/List';
-import { Cast, ScriptCast } from '../../fields/Types';
-import { denormalizeEmail, distributeAcls, GetEffectiveAcl, inheritParentAcls, SharingPermissions } from '../../fields/util';
+import { Cast, DocCast, ScriptCast, StrCast } from '../../fields/Types';
+import { denormalizeEmail, distributeAcls, GetEffectiveAcl, inheritParentAcls, normalizeEmail, SharingPermissions } from '../../fields/util';
import { returnFalse } from '../../Utils';
import { DocUtils } from '../documents/Documents';
import { DocumentType } from '../documents/DocumentTypes';
@@ -12,6 +12,7 @@ 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 {
@@ -191,24 +192,37 @@ export function ViewBoxAnnotatableComponent<P extends ViewBoxAnnotatableProps>()
}
const added = docs;
if (added.length) {
- const aclKeys = Object.keys(this.props.Document[DocAcl] ?? {});
+ const aclKeys = Object.keys(Doc.GetProto(this.props.Document)[DocAcl] ?? {});
+
aclKeys.forEach(key =>
added.forEach(d => {
- if (d.author === denormalizeEmail(key.substring(4)) && !d.createdFrom) {
- distributeAcls(key, SharingPermissions.Admin, 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))
}
})
);
if (effectiveAcl === AclAugment) {
added.map(doc => {
- if ([AclAdmin, AclEdit].includes(GetEffectiveAcl(doc)) && Doc.ActiveDashboard) inheritParentAcls(Doc.ActiveDashboard, doc);
doc.embedContainer = this.props.Document;
if (annotationKey ?? this._annotationKeySuffix()) Doc.GetProto(doc).annotationOn = this.props.Document;
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);
+ }
+ }
});
- } else {
- added
+ } else {
+ added
.filter(doc => [AclAdmin, AclEdit].includes(GetEffectiveAcl(doc)))
.map(doc => {
// only make a pushpin if we have acl's to edit the document
@@ -216,9 +230,18 @@ export function ViewBoxAnnotatableComponent<P extends ViewBoxAnnotatableProps>()
doc._dragOnlyWithinContainer = undefined;
doc.embedContainer = this.props.Document;
if (annotationKey ?? this._annotationKeySuffix()) Doc.GetProto(doc).annotationOn = this.rootDoc;
-
- Doc.ActiveDashboard && inheritParentAcls(Doc.ActiveDashboard, doc);
- });
+ 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);
+ }
+ }
+ });
+
const annoDocs = targetDataDoc[annotationKey ?? this.annotationKey] as List<Doc>;
if (annoDocs instanceof List) annoDocs.push(...added.filter(add => !annoDocs.includes(add)));
else targetDataDoc[annotationKey ?? this.annotationKey] = new List<Doc>(added);