aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SharingManager.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/SharingManager.tsx')
-rw-r--r--src/client/util/SharingManager.tsx126
1 files changed, 109 insertions, 17 deletions
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 3c05af4bb..5e61f6d3c 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -12,6 +12,7 @@ import { Cast, NumCast, PromiseValue, StrCast } from '../../fields/Types';
import { distributeAcls, GetEffectiveAcl, normalizeEmail, SharingPermissions, TraceMobx } from '../../fields/util';
import { Utils } from '../../Utils';
import { DocServer } from '../DocServer';
+import { CollectionFreeFormView } from '../views/collections/collectionFreeForm';
import { CollectionView } from '../views/collections/CollectionView';
import { DictationOverlay } from '../views/DictationOverlay';
import { MainViewModal } from '../views/MainViewModal';
@@ -157,21 +158,42 @@ export class SharingManager extends React.Component<{}> {
const acl = `acl-${normalizeEmail(user.email)}`;
const myAcl = `acl-${Doc.CurrentUserEmailNormalized}`;
const isDashboard = DocListCast(Doc.MyDashboards.data).indexOf(target) !== -1;
+
+ // var docs: Doc[] = [];
+ // const dashboardList = SelectionManager.Views().length < 2 ? [target] : SelectionManager.Views().map(docView => docView.props.Document);
+ // const dashboard = dashboardList[0]
+ // docs.push(dashboard!)
+ // const tabs = DocListCast(dashboard?.data)
+ // tabs.forEach(tab => {
+ // docs.push(tab)
+ // var newDocs = DocListCast(tab.data)
+ // newDocs.forEach(newDoc =>
+ // docs.push(newDoc))
+ // })
+
+ // if (!docs){
+ // return null;
+ // }
const docs = SelectionManager.Views().length < 2 ? [target] : SelectionManager.Views().map(docView => docView.props.Document);
+
+ //var docs: Doc[] = [];
+ docs.push(targetDoc!)
+
+ // ! ensures it returns true if document has been shared successfully, false otherwise
return !docs
.map(doc => (this.layoutDocAcls ? doc : doc[DataSym]))
.map(doc => {
doc.author === Doc.CurrentUserEmail && !doc[myAcl] && distributeAcls(myAcl, SharingPermissions.Admin, doc, undefined, undefined, isDashboard);
-
+
if (permission === SharingPermissions.None) {
if (doc[acl] && doc[acl] !== SharingPermissions.None) doc.numUsersShared = NumCast(doc.numUsersShared, 1) - 1;
} else {
if (!doc[acl] || doc[acl] === SharingPermissions.None) doc.numUsersShared = NumCast(doc.numUsersShared, 0) + 1;
}
+ doc = targetDoc
distributeAcls(acl, permission as SharingPermissions, doc, undefined, undefined, isDashboard);
-
this.setDashboardBackground(doc, permission as SharingPermissions);
if (permission !== SharingPermissions.None) return Doc.AddDocToList(sharingDoc, storage, doc);
else return GetEffectiveAcl(doc, user.email) === AclPrivate && Doc.RemoveDocFromList(sharingDoc, storage, (doc.aliasOf as Doc) || doc);
@@ -190,8 +212,18 @@ export class SharingManager extends React.Component<{}> {
const acl = `acl-${key}`;
const isDashboard = DocListCast(Doc.MyDashboards.data).indexOf(target) !== -1;
- const docs = SelectionManager.Views().length < 2 ? [target] : SelectionManager.Views().map(docView => docView.props.Document);
-
+ var docs: Doc[] = [];
+ const dashboardList = SelectionManager.Views().length < 2 ? [this.targetDoc] : SelectionManager.Views().map(docView => docView.props.Document);
+ const dashboard = dashboardList[0]
+ const tabs = DocListCast(dashboard?.data)
+ tabs.forEach(tab => {
+ var newDocs = DocListCast(tab.data)
+ newDocs.forEach(newDoc => docs.push(newDoc))
+ })
+
+ if (!docs){
+ return null;
+ }
// ! ensures it returns true if document has been shared successfully, false otherwise
return !docs
.map(doc => (this.layoutDocAcls ? doc : doc[DataSym]))
@@ -334,13 +366,20 @@ export class SharingManager extends React.Component<{}> {
// targetDoc["acl-" + PublicKey] = permission;
// }
- // private get sharingUrl() {
- // if (!this.targetDoc) {
- // return undefined;
- // }
- // const baseUrl = Utils.prepend("/doc/" + this.targetDoc[Id]);
- // return `${baseUrl}?sharing=true`;
- // }
+ private get sharingUrl() {
+ if (!this.targetDoc) {
+ return undefined;
+ }
+ const baseUrl = Utils.prepend("/doc/" + this.targetDoc[Id]);
+ return `${baseUrl}?sharing=true`;
+ }
+
+ /**
+ * Copies the Public sharing url to the user's clipboard.
+ */
+ private copyURL = (e: any) => {
+ Utils.CopyText(this.sharingUrl!)
+ }
// copy = action(() => {
// if (this.sharingUrl) {
@@ -357,7 +396,7 @@ export class SharingManager extends React.Component<{}> {
if (!uniform) dropdownValues.unshift('-multiple-');
if (!override) dropdownValues.splice(dropdownValues.indexOf(SharingPermissions.Unset), 1);
return dropdownValues
- .filter(permission => !Doc.noviceMode || ![SharingPermissions.SelfEdit].includes(permission as any))
+ .filter(permission => permission != SharingPermissions.SelfEdit && (!Doc.noviceMode || ![SharingPermissions.SelfEdit].includes(permission as any)))
.map(permission => (
<option key={permission} value={permission}>
{permission}
@@ -422,6 +461,7 @@ export class SharingManager extends React.Component<{}> {
this.selectedUsers.forEach(user => {
if (user.value.includes(indType)) {
this.setInternalSharing(this.users.find(u => u.user.email === user.label)!, this.permissions);
+
} else {
this.setInternalGroupSharing(GroupManager.Instance.getGroup(user.label)!, this.permissions);
}
@@ -466,6 +506,7 @@ export class SharingManager extends React.Component<{}> {
if (!this.targetDoc) return null;
TraceMobx();
const groupList = GroupManager.Instance?.allGroups || [];
+
const sortedUsers = this.users
.slice()
.sort(this.sortUsers)
@@ -505,13 +546,48 @@ export class SharingManager extends React.Component<{}> {
// users in common between all docs
const commonKeys = intersection(...docs.map(doc => (this.layoutDocAcls ? doc : doc[DataSym])).map(doc => doc?.[AclSym] && Object.keys(doc[AclSym])));
+ // including all users on dashboard
+ // SharingManager.Instance.users.forEach(eachUser => {
+ // var userOnDashboard = true;
+ // if(Doc.ActiveDashboard){
+ // if(Doc.ActiveDashboard['acl-'+normalizeEmail(eachUser.user.email)]=='' || Doc.ActiveDashboard['acl-'+normalizeEmail(eachUser.user.email)]==undefined){
+ // userOnDashboard = false;
+ // }
+ // }
+ // if (userOnDashboard && !commonKeys.includes(`acl-${normalizeEmail(eachUser.user.email)}`)){
+ // users.push(eachUser.user);
+ // }
+ // });
+
+
// the list of users shared with
const userListContents: (JSX.Element | null)[] = users
- .filter(({ user }) => (docs.length > 1 ? commonKeys.includes(`acl-${normalizeEmail(user.email)}`) : docs[0]?.author !== user.email))
+ // .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
+
+ // const tabs = DocListCast(dashboard?.data)
+ // tabs.forEach(tab => {
+ // if (tab.title == targetDoc.title){
+ // docToUse = tab
+ // }
+ // var newdocsList = DocListCast(tab.data)
+ // newdocsList.forEach(newDoc => {
+ // if (newDoc.title == targetDoc.title){
+ // docToUse = newDoc
+ // }
+ // })
+ // })
+
+ docToUse = Doc.GetProto(this.targetDoc!)
+
const userKey = `acl-${normalizeEmail(user.email)}`;
const uniform = docs.map(doc => (this.layoutDocAcls ? doc : doc[DataSym])).every(doc => doc?.[AclSym]?.[userKey] === docs[0]?.[AclSym]?.[userKey]);
- const permissions = uniform ? StrCast(targetDoc?.[userKey]) : '-multiple-';
+ const permissions = uniform ? StrCast(docToUse?.[userKey]) : '-multiple-';
return !permissions ? null : (
<div key={userKey} className={'container'}>
@@ -551,7 +627,7 @@ export class SharingManager extends React.Component<{}> {
</div>
) : null
);
-
+
// the list of groups shared with
const groupListMap: (Doc | { title: string })[] = groups.filter(({ title }) => (docs.length > 1 ? commonKeys.includes(`acl-${normalizeEmail(StrCast(title))}`) : true));
groupListMap.unshift({ title: 'Public' }); //, { title: "ALL" });
@@ -560,11 +636,27 @@ export class SharingManager extends React.Component<{}> {
const uniform = docs
.map(doc => (this.layoutDocAcls ? doc : doc[DataSym]))
.every(doc => (this.layoutDocAcls ? doc?.[AclSym]?.[groupKey] === docs[0]?.[AclSym]?.[groupKey] : doc?.[DataSym]?.[AclSym]?.[groupKey] === docs[0]?.[DataSym]?.[AclSym]?.[groupKey]));
- const permissions = uniform ? StrCast(targetDoc?.[`acl-${StrCast(group.title)}`]) : '-multiple-';
+ const permissions = uniform ? StrCast(targetDoc?.[groupKey]) : '-multiple-';
return !permissions ? null : (
<div key={groupKey} className={'container'}>
- <div className={'padding'}>{StrCast(group.title)}</div>
+ <div className={'padding'} >{StrCast(group.title)}</div>
+ <div>
+ {StrCast(group.title)==='Public' ? (
+ <div title={"Copy Public URL"} onClick={this.copyURL}>
+ {/* <IconButton
+ size={Size.SMALL}
+ isCircle={true}
+ hoverStyle="gray"
+ onClick={() => this.copyURL}
+ icon={<FontAwesomeIcon icon="copy" />}
+ /> */}
+ <FontAwesomeIcon icon={'copy'} size={'sm'} />
+ </div>
+ ) : (
+ <div/>
+ )}
+ </div>
{group instanceof Doc ? (
<div className="group-info" onClick={action(() => (GroupManager.Instance.currentGroup = group))}>
<FontAwesomeIcon icon={'info-circle'} color={'#e8e8e8'} size={'sm'} style={{ backgroundColor: '#1e89d7', borderRadius: '100%', border: '1px solid #1e89d7' }} />