aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-07-30 18:33:19 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-07-30 18:33:19 +0530
commit611f848ff4f7b958dc913d33dd1b760ca9474c44 (patch)
treef8b3749634903843813b085a5e4e0c96278d9b82
parent4224ebd13aec9e01f1fe73c935c40adb089dbc69 (diff)
permissions from the properties panel should work now
-rw-r--r--src/client/util/GroupManager.tsx2
-rw-r--r--src/client/util/SharingManager.tsx29
-rw-r--r--src/client/views/collections/collectionFreeForm/PropertiesView.scss2
-rw-r--r--src/client/views/collections/collectionFreeForm/PropertiesView.tsx56
-rw-r--r--src/fields/util.ts12
5 files changed, 67 insertions, 34 deletions
diff --git a/src/client/util/GroupManager.tsx b/src/client/util/GroupManager.tsx
index 72fba5c1b..dee0f105f 100644
--- a/src/client/util/GroupManager.tsx
+++ b/src/client/util/GroupManager.tsx
@@ -101,7 +101,7 @@ export default class GroupManager extends React.Component<{}> {
*/
@action
open = () => {
- SelectionManager.DeselectAll();
+ // SelectionManager.DeselectAll();
this.isOpen = true;
this.populateUsers();
this.populateGroups();
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 0d8b33fbe..9222f10c5 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -62,14 +62,12 @@ export default class SharingManager extends React.Component<{}> {
@observable private groupSort: "ascending" | "descending" | "none" = "none";
private shareDocumentButtonRef: React.RefObject<HTMLButtonElement> = React.createRef();
-
-
// private get linkVisible() {
// return this.sharingDoc ? this.sharingDoc[PublicKey] !== SharingPermissions.None : false;
// }
public open = (target: DocumentView) => {
- SelectionManager.DeselectAll();
+ // SelectionManager.DeselectAll();
this.populateUsers().then(action(() => {
this.targetDocView = target;
this.targetDoc = target.props.Document;
@@ -82,7 +80,7 @@ export default class SharingManager extends React.Component<{}> {
public close = action(() => {
this.isOpen = false;
- this.users = [];
+ // this.users = [];
this.selectedUsers = null;
setTimeout(action(() => {
@@ -97,7 +95,12 @@ export default class SharingManager extends React.Component<{}> {
SharingManager.Instance = this;
}
+ componentDidMount() {
+ this.populateUsers();
+ }
+
populateUsers = async () => {
+ runInAction(() => this.users = []);
const userList = await RequestPromise.get(Utils.prepend("/getUsers"));
const raw = JSON.parse(userList) as User[];
const evaluating = raw.map(async user => {
@@ -117,17 +120,17 @@ export default class SharingManager extends React.Component<{}> {
return Promise.all(evaluating);
}
- setInternalGroupSharing = (group: Doc, permission: string) => {
+ setInternalGroupSharing = (group: Doc, permission: string, targetDoc?: Doc) => {
const members: string[] = JSON.parse(StrCast(group.members));
const users: ValidatedUser[] = this.users.filter(({ user: { email } }) => members.includes(email));
- const target = this.targetDoc!;
+ const target = targetDoc || this.targetDoc!;
const ACL = `ACL-${StrCast(group.groupName)}`;
// fix this - not needed (here and setinternalsharing and removegroup)
// target[ACL] = permission;
// Doc.GetProto(target)[ACL] = permission;
- distributeAcls(ACL, permission as SharingPermissions, this.targetDoc!);
+ distributeAcls(ACL, permission as SharingPermissions, target);
group.docsShared ? DocListCastAsync(group.docsShared).then(resolved => Doc.IndexOf(target, resolved!) === -1 && (group.docsShared as List<Doc>).push(target)) : group.docsShared = new List<Doc>([target]);
@@ -182,14 +185,20 @@ export default class SharingManager extends React.Component<{}> {
}
}
+ shareFromPropertiesSidebar = (shareWith: string, permission: SharingPermissions, target: Doc) => {
+ const user = this.users.find(({ user: { email } }) => email === (shareWith === "Me" ? Doc.CurrentUserEmail : shareWith));
+ if (user) this.setInternalSharing(user, permission, target);
+ else this.setInternalGroupSharing(GroupManager.Instance.getGroup(shareWith)!, permission, target);
+ }
+
// @action
- setInternalSharing = (recipient: ValidatedUser, permission: string) => {
+ setInternalSharing = (recipient: ValidatedUser, permission: string, targetDoc?: Doc) => {
const { user, notificationDoc } = recipient;
- const target = this.targetDoc!;
+ const target = targetDoc || this.targetDoc!;
const key = user.email.replace('.', '_');
const ACL = `ACL-${key}`;
- distributeAcls(ACL, permission as SharingPermissions, this.targetDoc!);
+ distributeAcls(ACL, permission as SharingPermissions, target);
if (permission !== SharingPermissions.None) {
DocListCastAsync(notificationDoc[storage]).then(resolved => {
diff --git a/src/client/views/collections/collectionFreeForm/PropertiesView.scss b/src/client/views/collections/collectionFreeForm/PropertiesView.scss
index cb4b7375b..4ccc0950b 100644
--- a/src/client/views/collections/collectionFreeForm/PropertiesView.scss
+++ b/src/client/views/collections/collectionFreeForm/PropertiesView.scss
@@ -159,6 +159,8 @@
border-radius: 6px;
width: 170px;
background-color: #ececec;
+ max-height: 130px;
+ overflow-y: scroll;
.propertiesView-sharingTable-item {
diff --git a/src/client/views/collections/collectionFreeForm/PropertiesView.tsx b/src/client/views/collections/collectionFreeForm/PropertiesView.tsx
index d5317efcb..b33b37f4b 100644
--- a/src/client/views/collections/collectionFreeForm/PropertiesView.tsx
+++ b/src/client/views/collections/collectionFreeForm/PropertiesView.tsx
@@ -2,7 +2,7 @@ import React = require("react");
import { observer } from "mobx-react";
import "./PropertiesView.scss";
import { observable, action, computed, runInAction } from "mobx";
-import { Doc, Field, DocListCast, WidthSym, HeightSym } from "../../../../fields/Doc";
+import { Doc, Field, DocListCast, WidthSym, HeightSym, AclSym, AclPrivate, AclReadonly, AclAddonly, AclEdit, AclAdmin } from "../../../../fields/Doc";
import { DocumentView } from "../../nodes/DocumentView";
import { ComputedField } from "../../../../fields/ScriptField";
import { EditableView } from "../../EditableView";
@@ -18,6 +18,7 @@ import { SelectionManager } from "../../../util/SelectionManager";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Tooltip, Checkbox } from "@material-ui/core";
import SharingManager from "../../../util/SharingManager";
+import { SharingPermissions, GetEffectiveAcl } from "../../../../fields/util";
interface PropertiesViewProps {
@@ -249,20 +250,15 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
}
}
- @computed get permissionsSelect() {
- return <select className="permissions-select" onChange={emptyFunction}>
- <option key={"Can Edit"} value={"Can Edit"}>
- Can Edit
- </option>
- <option key={"Can Add"} value={"Can Add"}>
- Can Add
- </option>
- <option key={"Can View"} value={"Can View"}>
- Can View
- </option>
- <option key={"Not Shared"} value={"Not Shared"}>
- Not Shared
- </option>
+ getPermissionsSelect(user: string) {
+ return <select className="permissions-select"
+ onChange={e => SharingManager.Instance.shareFromPropertiesSidebar(user, e.currentTarget.value as SharingPermissions, this.selectedDoc!)}>
+ {Object.values(SharingPermissions).map(permission => {
+ return (
+ <option key={permission} value={permission} selected={this.selectedDoc![`ACL-${user.replace(".", "_")}`] === permission}>
+ {permission}
+ </option>);
+ })}
</select>;
}
@@ -286,23 +282,41 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
</Tooltip>;
}
- sharingItem(name: string, notify: boolean, editable: boolean, permission?: string) {
+ sharingItem(name: string, notify: boolean, effectiveAcl: symbol, permission?: string) {
return <div className="propertiesView-sharingTable-item">
<div className="propertiesView-sharingTable-item-name" style={{ width: notify ? "70px" : "80px" }}> {name} </div>
{notify ? this.notifyIcon : null}
<div className="propertiesView-sharingTable-item-permission">
- {editable ? this.permissionsSelect : permission}
+ {effectiveAcl === AclAdmin && permission !== "Owner" ? this.getPermissionsSelect(name) : permission}
{permission === "Owner" ? this.expansionIcon : null}
</div>
</div>;
}
@computed get sharingTable() {
+ const AclMap = new Map<symbol, string>([
+ [AclPrivate, SharingPermissions.None],
+ [AclReadonly, SharingPermissions.View],
+ [AclAddonly, SharingPermissions.Add],
+ [AclEdit, SharingPermissions.Edit],
+ [AclAdmin, SharingPermissions.Admin]
+ ]);
+
+ const effectiveAcl = GetEffectiveAcl(this.selectedDoc!);
+ const tableEntries = [];
+
+ if (this.selectedDoc![AclSym]) {
+ for (const [key, value] of Object.entries(this.selectedDoc![AclSym])) {
+ const name = key.substring(4).replace("_", ".");
+ if (name !== Doc.CurrentUserEmail && name !== this.selectedDoc!.author) tableEntries.push(this.sharingItem(name, false, effectiveAcl, AclMap.get(value)!));
+ }
+ }
+
+ tableEntries.unshift(this.sharingItem("Me", false, effectiveAcl, Doc.CurrentUserEmail === this.selectedDoc!.author ? "Owner" : StrCast(this.selectedDoc![`ACL-${Doc.CurrentUserEmail.replace(".", "_")}`])));
+ if (Doc.CurrentUserEmail !== this.selectedDoc!.author) tableEntries.unshift(this.sharingItem(StrCast(this.selectedDoc!.author), false, effectiveAcl, "Owner"));
+
return <div className="propertiesView-sharingTable">
- {this.sharingItem("Me", false, false, "Owner")}
- {this.sharingItem("Public", false, true)}
- {this.sharingItem("Group 1", true, true)}
- {this.sharingItem("Group 2", true, true)}
+ {tableEntries}
</div>;
}
diff --git a/src/fields/util.ts b/src/fields/util.ts
index a62795e64..267da70b4 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -1,5 +1,5 @@
import { UndoManager } from "../client/util/UndoManager";
-import { Doc, FieldResult, UpdatingFromServer, LayoutSym, AclPrivate, AclEdit, AclReadonly, AclAddonly, AclSym, CachedUpdates, DataSym, DocListCast, AclAdmin, FieldsSym, HeightSym, WidthSym } from "./Doc";
+import { Doc, FieldResult, UpdatingFromServer, LayoutSym, AclPrivate, AclEdit, AclReadonly, AclAddonly, AclSym, CachedUpdates, DataSym, DocListCast, AclAdmin, FieldsSym, HeightSym, WidthSym, fetchProto } from "./Doc";
import { SerializationHelper } from "../client/util/SerializationHelper";
import { ProxyField, PrefetchProxy } from "./Proxy";
import { RefField } from "./RefField";
@@ -183,12 +183,18 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc
["Admin", 4]
]);
+ let changed = false;
+
const dataDoc = target[DataSym];
- if (!inheritingFromCollection || !target[key] || HierarchyMapping.get(StrCast(target[key]))! > HierarchyMapping.get(acl)!) target[key] = acl;
+ if (!inheritingFromCollection || !target[key] || HierarchyMapping.get(StrCast(target[key]))! > HierarchyMapping.get(acl)!) {
+ target[key] = acl;
+ changed = true;
+ }
if (dataDoc && (!inheritingFromCollection || !dataDoc[key] || HierarchyMapping.get(StrCast(dataDoc[key]))! > HierarchyMapping.get(acl)!)) {
dataDoc[key] = acl;
+ changed = true;
DocListCast(dataDoc[Doc.LayoutFieldKey(dataDoc)]).map(d => {
if (d.author === Doc.CurrentUserEmail && (!inheritingFromCollection || !d[key] || HierarchyMapping.get(StrCast(d[key]))! > HierarchyMapping.get(acl)!)) {
@@ -214,6 +220,8 @@ export function distributeAcls(key: string, acl: SharingPermissions, target: Doc
}
});
}
+
+ changed && fetchProto(target);
}
const layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeight", "fitWidth", "fitToBox",