diff options
Diffstat (limited to 'src/client/views/PropertiesView.tsx')
-rw-r--r-- | src/client/views/PropertiesView.tsx | 124 |
1 files changed, 87 insertions, 37 deletions
diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index dfc43e6c8..a6a5347ad 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -13,7 +13,7 @@ import { InkField } from '../../fields/InkField'; import { List } from '../../fields/List'; import { ComputedField } from '../../fields/ScriptField'; import { Cast, DocCast, NumCast, StrCast } from '../../fields/Types'; -import { denormalizeEmail, GetEffectiveAcl, SharingPermissions } from '../../fields/util'; +import { denormalizeEmail, GetEffectiveAcl, normalizeEmail, SharingPermissions } from '../../fields/util'; import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue, setupMoveUpEvents } from '../../Utils'; import { DocumentType } from '../documents/DocumentTypes'; import { DocumentManager } from '../util/DocumentManager'; @@ -34,6 +34,7 @@ import { PropertiesDocBacklinksSelector } from './PropertiesDocBacklinksSelector import { PropertiesDocContextSelector } from './PropertiesDocContextSelector'; import './PropertiesView.scss'; import { DefaultStyleProvider } from './StyleProvider'; +import { SourceMapDevToolPlugin } from 'webpack'; const higflyout = require('@hig/flyout'); export const { anchorPoints } = higflyout; export const Flyout = higflyout.default; @@ -366,11 +367,12 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { */ @undoBatch changePermissions = (e: any, user: string) => { + const docs = (SelectionManager.Views().length < 2 ? [this.selectedDoc] : SelectionManager.Views().map(dv => dv.props.Document)).filter(doc => doc).map(doc => (this.layoutDocAcls ? doc : DocCast(doc)[DataSym])); if (user=="Public"){ - this.selectedDoc!['acl-' +user] = e.currentTarget.value as SharingPermissions; + docs[0]['acl-' +user] = e.currentTarget.value as SharingPermissions; } else{ - const docs = (SelectionManager.Views().length < 2 ? [this.selectedDoc] : SelectionManager.Views().map(dv => dv.props.Document)).filter(doc => doc).map(doc => (this.layoutDocAcls ? doc : DocCast(doc)[DataSym])); + SharingManager.Instance.shareFromPropertiesSidebar(user, e.currentTarget.value as SharingPermissions, docs); } }; @@ -381,15 +383,17 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { getPermissionsSelect(user: string, permission: string) { const dropdownValues: string[] = Object.values(SharingPermissions); if (permission === '-multiple-') dropdownValues.unshift(permission); - if (user !== 'Override') dropdownValues.splice(dropdownValues.indexOf(SharingPermissions.Unset), 1); + if (user !== 'Override') { + dropdownValues.splice(dropdownValues.indexOf(SharingPermissions.Unset), 1); + // dropdownValues.splice(dropdownValues.indexOf(SharingPermissions.Unset), 1); + } return ( <select className="propertiesView-permissions-select" value={permission} onChange={e => this.changePermissions(e, user)}> {dropdownValues - .filter(permission => !Doc.noviceMode || ![SharingPermissions.View, SharingPermissions.SelfEdit].includes(permission as any)) + .filter(permission => permission != SharingPermissions.SelfEdit && (!Doc.noviceMode || ![SharingPermissions.View, SharingPermissions.SelfEdit].includes(permission as any))) .map(permission => ( <option className="propertiesView-permisssions-select" key={permission} value={permission}> - {' '} - {permission}{' '} + {' '}{permission}{' '} </option> ))} </select> @@ -432,6 +436,9 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { * @returns a row of the permissions panel */ sharingItem(name: string, admin: boolean, permission: string, showExpansionIcon?: boolean) { + if (name==Doc.CurrentUserEmail){ + name = 'Me'; + } return ( <div className="propertiesView-sharingTable-item" @@ -445,7 +452,7 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { {/* {name !== "Me" ? this.notifyIcon : null} */} <div className="propertiesView-sharingTable-item-permission"> {admin && permission !== 'Owner' ? this.getPermissionsSelect(name, permission) : permission} - {permission === 'Owner' || showExpansionIcon ? this.expansionIcon : null} + {(permission === 'Owner' && name=='Me')|| showExpansionIcon ? this.expansionIcon : null} </div> </div> ); @@ -470,6 +477,7 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { dropDownText = "▲ "; break; } + return ( <div> <div className={'propertiesView-shareDropDown'}> @@ -490,7 +498,24 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { */ @computed get sharingTable() { // const docToUse = this.selectedDocumentView?.rootDoc; + + // const dashboard = Doc.ActiveDashboard + // var docToUse = dashboard + // const tabs = DocListCast(dashboard?.data) + // tabs.forEach(tab => { + // if (tab.title == this.selectedDoc?.title){ + // docToUse = tab + // } + // var newdocsList = DocListCast(tab.data) + // newdocsList.forEach(newDoc => { + // if (newDoc.title == this.selectedDoc?.title){ + // docToUse = newDoc + // } + // }) + // }) + const docToUse = this.selectedDoc; + if (!docToUse){ return null; } @@ -501,44 +526,69 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { const target = docs[0]; // tslint:disable-next-line: no-unnecessary-callback-wrapper - const effectiveAcls = docs.map(doc => GetEffectiveAcl(doc)); - const showAdmin = effectiveAcls.every(acl => acl === AclAdmin); + // const effectiveAcls = docs.map(doc => GetEffectiveAcl(doc)); + // const effectiveAcls = GetEffectiveAcl(docToUse) + const effectiveAcls = GetEffectiveAcl(target) + + // const showAdmin = effectiveAcls.every(acl => acl === AclAdmin); + const showAdmin= effectiveAcls==AclAdmin || docToUse!['acl-'+normalizeEmail(Doc.CurrentUserEmail)]=='Owner'; // users in common between all docs const commonKeys: string[] = intersection(...docs.map(doc => doc?.[AclSym] && Object.keys(doc[AclSym]).filter(key => key !== 'acl-Me'))); const tableEntries = []; + const usersAdded: string[] = []; // all shared users being added - organized by denormalized email + const ownerSame = Doc.CurrentUserEmail !== target.author && docs.filter(doc => doc).every(doc => doc.author === docs[0].author); + + usersAdded.push(target.author); + SharingManager.Instance.users.forEach(eachUser => { + var userOnDashboard = true; + var permission = StrCast(target[`acl-${normalizeEmail(eachUser.user.email)}`]) + if(Doc.ActiveDashboard){ + if(Doc.ActiveDashboard['acl-'+normalizeEmail(eachUser.user.email)]=='' || Doc.ActiveDashboard['acl-'+normalizeEmail(eachUser.user.email)]==undefined){ + userOnDashboard = false; + } + } + if (userOnDashboard && !usersAdded.includes(eachUser.user.email) && eachUser.user.email!='Public'){ + tableEntries.unshift(this.sharingItem(eachUser.user.email, showAdmin, permission, false)); // adds each user + usersAdded.push(eachUser.user.email); + } + }); - // DocCastAsync(Doc.UserDoc().sidebarUsersDisplayed).then(sidebarUsersDisplayed => { - // if (commonKeys.length) { - // for (const key of commonKeys) { - // const name = denormalizeEmail(key.substring(4)); - // const uniform = docs.every(doc => doc?.[AclSym]?.[key] === docs[0]?.[AclSym]?.[key]); - // if (name !== Doc.CurrentUserEmail && name !== target.author && name !== 'Public' && name !== 'Override' /* && sidebarUsersDisplayed![name] !== false*/) { - // tableEntries.push(this.sharingItem(name, showAdmin, uniform ? HierarchyMapping.get(target[AclSym][key])!.name : '-multiple-')); + // commonKeys.forEach(user => { + // const userEmail = user.slice(4) + // var userOnDashboard = true; + // if(Doc.ActiveDashboard){ + // if(Doc.ActiveDashboard[user]=='' || Doc.ActiveDashboard[user]==undefined){ + // userOnDashboard = false; // } // } - // } - const ownerSame = Doc.CurrentUserEmail !== target.author && docs.filter(doc => doc).every(doc => doc.author === docs[0].author); - // shifts the current user, owner, public to the top of the doc. - // tableEntries.unshift(this.sharingItem("Override", showAdmin, docs.filter(doc => doc).every(doc => doc["acl-Override"] === docs[0]["acl-Override"]) ? (AclMap.get(target[AclSym]?.["acl-Override"]) || "None") : "-multiple-")); - if (ownerSame) tableEntries.unshift(this.sharingItem(StrCast(target.author), showAdmin, 'Owner')); - // tableEntries.unshift(this.sharingItem(target.author, showAdmin, docs.filter(doc => doc).every(doc => doc['acl-Public'] === target['acl-Public']) ? target['acl-Public'] || SharingPermissions.None : '-multiple-')); - // tableEntries.unshift( - // this.sharingItem( - // 'Me', - // showAdmin, - // docs.filter(doc => doc).every(doc => doc.author === Doc.CurrentUserEmail) ? 'Owner' : effectiveAcls.every(acl => acl === effectiveAcls[0]) ? HierarchyMapping.get(effectiveAcls[0])!.name : '-multiple-', - // !ownerSame - // ) - // ); - - SharingManager.Instance.users.forEach(eachUser => tableEntries.unshift(this.sharingItem(eachUser.user.email, false, "test", false))); - - docs.map(doc => tableEntries.unshift(this.sharingItem(doc.author, showAdmin, 'Owner', true))); + // if (userOnDashboard && !usersAdded.includes(denormalizeEmail(userEmail)) && userEmail!='Public'){ + // tableEntries.unshift(this.sharingItem(denormalizeEmail(userEmail), showAdmin, StrCast(docToUse![`acl-${normalizeEmail((userEmail))}`]), false)); // adds each user + // usersAdded.push(denormalizeEmail(userEmail)); + // } + // }) + + // current user + const userEmail = Doc.CurrentUserEmail + var userOnDashboard = true; + if(Doc.ActiveDashboard){ + if(Doc.ActiveDashboard['acl-'+normalizeEmail(userEmail)]=='' || Doc.ActiveDashboard['acl-'+normalizeEmail(userEmail)]==undefined){ + userOnDashboard = false; + } + } + if (userOnDashboard && !usersAdded.includes(denormalizeEmail(userEmail)) && userEmail!='Public'){ + tableEntries.unshift(this.sharingItem(denormalizeEmail(userEmail), showAdmin, StrCast(target[`acl-${normalizeEmail((userEmail))}`]), false)); // adds each user + usersAdded.push(denormalizeEmail(userEmail)); + } + + // if (ownerSame ) tableEntries.unshift(this.sharingItem(StrCast(target.author), showAdmin, 'Owner'), false); // shift owner to top + tableEntries.unshift(this.sharingItem(StrCast(target.author), showAdmin, 'Owner'), false); // shift owner to top return ( - <div> Sharing Mode - <div>{this.publicACLDropDown(true, StrCast(docToUse['acl-Public']), false)}</div> + <div > Sharing Mode + <div>{ + this.publicACLDropDown(true, StrCast(target['acl-Public']), false)} + </div> <div> <br></br> Who has access to the Dashboard? </div> <div className="propertiesView-sharingTable">{ <div> {tableEntries}</div> |