From a217c9261990cb751119ae68e7dcc7e32f48e529 Mon Sep 17 00:00:00 2001 From: srichman333 Date: Fri, 16 Jun 2023 11:13:52 -0400 Subject: cleaner w/ effectiveAcls --- src/client/util/SharingManager.tsx | 19 ++++++------------- src/client/views/DocComponent.tsx | 14 +++++++++----- src/client/views/DocumentDecorations.tsx | 5 ++--- src/client/views/PropertiesView.tsx | 1 - src/client/views/topbar/TopBar.tsx | 2 +- src/fields/util.ts | 32 ++++++++++++++------------------ 6 files changed, 32 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx index 6cbc060fa..a161b4dc2 100644 --- a/src/client/util/SharingManager.tsx +++ b/src/client/util/SharingManager.tsx @@ -80,7 +80,7 @@ export class SharingManager extends React.Component<{}> { @observable private showGroupOptions: boolean = false; // // whether to show groups as options when sharing (in the react-select component) private populating: boolean = false; // whether the list of users is populating or not @observable private layoutDocAcls: boolean = false; // whether the layout doc or data doc's acls are to be used - @observable private overridePrivate: boolean = false; // whether child docs in a collection/dashboard should be changed to be less private + @observable private overridePrevious: boolean = false; // whether child docs in a collection/dashboard should be changed to be less private @observable private myDocAcls: boolean = false; // whether the My Docs checkbox is selected or not // private get linkVisible() { @@ -160,10 +160,10 @@ export class SharingManager extends React.Component<{}> { const isDashboard = DocListCast(Doc.MyDashboards.data).indexOf(target) !== -1; // setting the same acl for a docs within the doc being shared if they haven't been set yet - // or if the 'Override Private' checkbox is selected + // or if the 'Override previous' checkbox is selected var childDocs = DocListCast(target.data); childDocs.map(doc => { - if (this.overridePrivate || doc[acl]==undefined){ + if (this.overridePrevious || doc[acl]==undefined){ this.setInternalSharing(recipient, permission, doc); } }); @@ -204,7 +204,7 @@ export class SharingManager extends React.Component<{}> { // or if the 'Override Private' checkbox is selected var childDocs = DocListCast(target.data); childDocs.map(doc => { - if (this.overridePrivate || doc[acl]==undefined){ + if (this.overridePrevious || doc[acl]==undefined){ this.setInternalGroupSharing(group, permission, doc); } }); @@ -279,7 +279,7 @@ export class SharingManager extends React.Component<{}> { const dashboards = DocListCast(Doc.MyDashboards.data); docs.forEach(doc => { const isDashboard = dashboards.indexOf(doc) !== -1; - if (this.overridePrivate) this.shareFromPropertiesSidebar(shareWith, permission, DocListCast(doc.data)); + if (this.overridePrevious) this.shareFromPropertiesSidebar(shareWith, permission, DocListCast(doc.data)); if (GetEffectiveAcl(doc) === AclAdmin) distributeAcls(`acl-${shareWith}`, permission, doc, undefined, undefined, isDashboard); this.setDashboardBackground(doc, permission as SharingPermissions); }); @@ -520,13 +520,6 @@ export class SharingManager extends React.Component<{}> { // .filter(({ user }) => (docs.length > 1 ? commonKeys.includes(`acl-${normalizeEmail(user.email)}`) : docs[0]?.author !== user.email)) .filter(({ user }) => docs[0]?.author !== user.email) .map(({ user, linkDatabase, sharingDoc, userColor }) => { - const dashboardList = SelectionManager.Views().length < 2 ? [targetDoc] : SelectionManager.Views().map(docView => docView.props.Document); - // const dashboard = dashboardList[0] - const dashboard = Doc.ActiveDashboard; - var docToUse = dashboard; - - docToUse = Doc.GetProto(this.targetDoc!); - const userKey = `acl-${normalizeEmail(user.email)}`; const uniform = docs.map(doc => (this.layoutDocAcls ? doc : doc[DocData])).every(doc => doc?.[DocAcl]?.[userKey] === docs[0]?.[DocAcl]?.[userKey]); const permissions = uniform ? StrCast(targetDoc?.[userKey]) : '-multiple-'; @@ -647,7 +640,7 @@ export class SharingManager extends React.Component<{}> {
{Doc.noviceMode ? null : (
- (this.overridePrivate = !this.overridePrivate))} checked={this.overridePrivate} /> + (this.overridePrevious = !this.overridePrevious))} checked={this.overridePrevious} /> (this.layoutDocAcls = !this.layoutDocAcls))} checked={this.layoutDocAcls} />
)} diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx index db24229dc..7e8946ca0 100644 --- a/src/client/views/DocComponent.tsx +++ b/src/client/views/DocComponent.tsx @@ -1,9 +1,9 @@ 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 { Cast, ScriptCast, StrCast } from '../../fields/Types'; import { denormalizeEmail, distributeAcls, GetEffectiveAcl, inheritParentAcls, SharingPermissions } from '../../fields/util'; import { returnFalse } from '../../Utils'; import { DocUtils } from '../documents/Documents'; @@ -191,11 +191,15 @@ export function ViewBoxAnnotatableComponent

() } 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, d) } }) ); diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index ff98e18d4..8e224a4b6 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -7,7 +7,7 @@ import { observer } from 'mobx-react'; import { FaUndo } from 'react-icons/fa'; import { Utils, aggregateBounds, emptyFunction, numberValue, returnFalse, setupMoveUpEvents } from '../../Utils'; import { DateField } from '../../fields/DateField'; -import { Doc, DocListCast, Field } from '../../fields/Doc'; +import { Doc, DocListCast, Field, HierarchyMapping } from '../../fields/Doc'; import { AclAdmin, AclAugment, AclEdit, DocData, Height, Width } from '../../fields/DocSymbols'; import { InkField } from '../../fields/InkField'; import { RichTextField } from '../../fields/RichTextField'; @@ -765,8 +765,7 @@ const dragDocView = SelectionManager.Views()[0]; } // sharing - // const docShareMode = Doc.GetProto(seldocview.rootDoc)['acl-Public']; - const docShareMode = Doc.GetProto(seldocview.rootDoc)['acl-' + normalizeEmail(Doc.CurrentUserEmail)]; + const docShareMode = HierarchyMapping.get(GetEffectiveAcl(seldocview.rootDoc))!.name const shareMode = StrCast(docShareMode); var shareSymbolIcon = null; switch (shareMode) { diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index 4674bc0f4..8648d84c2 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -499,7 +499,6 @@ export class PropertiesView extends React.Component { const groupKey = 'acl-' + normalizeEmail(StrCast(group.title)); if (Doc.ActiveDashboard[groupKey] != '' && Doc.ActiveDashboard[groupKey] != undefined) { const permission = StrCast(target[groupKey]); - console.log(permission) tableEntries.unshift(this.sharingItem(StrCast(group.title), showAdmin, permission, false)); } } diff --git a/src/client/views/topbar/TopBar.tsx b/src/client/views/topbar/TopBar.tsx index 71daad1a9..834156295 100644 --- a/src/client/views/topbar/TopBar.tsx +++ b/src/client/views/topbar/TopBar.tsx @@ -103,7 +103,7 @@ export class TopBar extends React.Component { }} />