diff options
Diffstat (limited to 'src/client/views/PropertiesView.tsx')
-rw-r--r-- | src/client/views/PropertiesView.tsx | 93 |
1 files changed, 30 insertions, 63 deletions
diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index a6a5347ad..984c2dc04 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -369,7 +369,8 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { 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"){ - docs[0]['acl-' +user] = e.currentTarget.value as SharingPermissions; + // docs[0]['acl-' +user] = e.currentTarget.value as SharingPermissions; + SharingManager.Instance.shareFromPropertiesSidebar(user, e.currentTarget.value as SharingPermissions, docs); } else{ @@ -385,12 +386,11 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { if (permission === '-multiple-') dropdownValues.unshift(permission); 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 => permission != SharingPermissions.SelfEdit && (!Doc.noviceMode || ![SharingPermissions.View, SharingPermissions.SelfEdit].includes(permission as any))) + .filter(permission => !Doc.noviceMode || ![SharingPermissions.View].includes(permission as any)) .map(permission => ( <option className="propertiesView-permisssions-select" key={permission} value={permission}> {' '}{permission}{' '} @@ -464,9 +464,6 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { case ("Edit"): dropDownText = "⬢ "; break; - case ("Self-Edit"): - dropDownText = "⬢ "; - break; case ("Augment"): dropDownText = "⬟ "; break; @@ -494,52 +491,35 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { } /** + * Sorting algorithm to sort users. + */ + sortUsers = (u1: String, u2: String) => { + return u1 > u2 ? -1 : u1 === u2 ? 0 : 1; + }; + + /** * @returns the sharing and permissions panel. */ @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; } // all selected docs const docs = SelectionManager.Views().length < 2 ? [this.layoutDocAcls ? docToUse : docToUse?.[DataSym]] : SelectionManager.Views().map(docView => (this.layoutDocAcls ? docView.props.Document : docView.props.Document[DataSym])); - const target = docs[0]; - // tslint:disable-next-line: no-unnecessary-callback-wrapper - // 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 commonKeys: string[] = intersection(...docs.map(doc => doc?.[AclSym] && Object.keys(doc[AclSym]).filter(key => key !== 'acl-Me'))); + // const ownerSame = Doc.CurrentUserEmail !== target.author && docs.filter(doc => doc).every(doc => doc.author === docs[0].author); 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)}`]) @@ -548,46 +528,33 @@ export class PropertiesView extends React.Component<PropertiesViewProps> { 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 + if (userOnDashboard && !usersAdded.includes(eachUser.user.email) && eachUser.user.email!='Public' && eachUser.user.email!=target.author){ + // tableEntries.unshift(this.sharingItem(eachUser.user.email, showAdmin, permission, false)); // adds each user usersAdded.push(eachUser.user.email); } }); - - // commonKeys.forEach(user => { - // const userEmail = user.slice(4) - // var userOnDashboard = true; - // if(Doc.ActiveDashboard){ - // if(Doc.ActiveDashboard[user]=='' || Doc.ActiveDashboard[user]==undefined){ - // userOnDashboard = false; - // } - // } - // 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)); + + usersAdded.sort(this.sortUsers) + usersAdded.map(userEmail => { + const permission = StrCast(target[`acl-${normalizeEmail(userEmail)}`]) + tableEntries.unshift(this.sharingItem(userEmail, showAdmin, permission, false)); // adds each user + }) + + // add current user + var userEmail = Doc.CurrentUserEmail + if (userEmail == 'guest') userEmail = 'Public'; + if (!usersAdded.includes(userEmail) && userEmail!='Public' && userEmail!=target.author){ + tableEntries.unshift(this.sharingItem(userEmail, showAdmin, StrCast(target[`acl-${normalizeEmail((userEmail))}`]), false)); // adds each user + usersAdded.push(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 + // shift owner to top + tableEntries.unshift(this.sharingItem(StrCast(target.author), showAdmin, 'Owner'), false); return ( <div > Sharing Mode <div>{ - this.publicACLDropDown(true, StrCast(target['acl-Public']), false)} + this.publicACLDropDown(showAdmin, StrCast(target['acl-Public']), false)} </div> <div> <br></br> Who has access to the Dashboard? </div> <div className="propertiesView-sharingTable">{ |