aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/CurrentUserUtils.ts6
-rw-r--r--src/client/util/SharingManager.tsx12
-rw-r--r--src/fields/util.ts26
3 files changed, 27 insertions, 17 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 759fd6eca..580c6040e 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -956,6 +956,9 @@ export class CurrentUserUtils {
}
static async updateUserDocument(doc: Doc, sharingDocumentId: string) {
+ if (!doc.globalGroupDatabase) doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument();
+ await DocListCastAsync((doc.globalGroupDatabase as Doc).data);
+ UserGroups.Current;
doc.system = true;
doc.noviceMode = doc.noviceMode === undefined ? "true" : doc.noviceMode;
doc.title = Doc.CurrentUserEmail;
@@ -989,10 +992,7 @@ export class CurrentUserUtils {
await this.setupSidebarButtons(doc); // the pop-out left sidebar of tools/panels
await this.setupMenuPanel(doc, sharingDocumentId);
if (!doc.globalScriptDatabase) doc.globalScriptDatabase = Docs.Prototypes.MainScriptDocument();
- doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument();
if (!doc.myLinkDatabase) doc.myLinkDatabase = new List([]);
- const x = await DocListCastAsync((doc.globalGroupDatabase as Doc).data);
- UserGroups.setCurrentUserGroups((doc.globalGroupDatabase as Doc).data as List<Doc>);
setTimeout(() => this.setupDefaultPresentation(doc), 0); // presentation that's initially triggered
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 729742890..ee397ab4f 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -4,7 +4,7 @@ import { observer } from "mobx-react";
import * as React from "react";
import Select from "react-select";
import * as RequestPromise from "request-promise";
-import { AclAdmin, AclPrivate, DataSym, Doc, DocListCast, Opt, AclSym, AclAddonly, AclEdit, AclReadonly } from "../../fields/Doc";
+import { AclAdmin, AclPrivate, DataSym, Doc, DocListCast, Opt, AclSym, AclAddonly, AclEdit, AclReadonly, DocListCastAsync } from "../../fields/Doc";
import { List } from "../../fields/List";
import { Cast, StrCast } from "../../fields/Types";
import { distributeAcls, GetEffectiveAcl, SharingPermissions, TraceMobx, normalizeEmail } from "../../fields/util";
@@ -189,7 +189,9 @@ export class SharingManager extends React.Component<{}> {
const self = this;
if (group.docsShared) {
if (!user) retry && this.populateUsers().then(() => self.shareWithAddedMember(group, emailId, false));
- else DocListCast(group.docsShared).forEach(doc => Doc.IndexOf(doc, DocListCast(user.sharingDoc[storage])) === -1 && Doc.AddDocToList(user.sharingDoc, storage, doc));
+ else DocListCastAsync(group.docsShared).then(dl => dl?.forEach(doc => {
+ Doc.AddDocToList(user.sharingDoc, storage, doc);
+ }));
}
}
@@ -220,9 +222,9 @@ export class SharingManager extends React.Component<{}> {
const user: ValidatedUser = this.users.find(({ user: { email } }) => email === emailId)!;
if (group.docsShared) {
- DocListCast(group.docsShared).forEach(doc => {
- Doc.IndexOf(doc, DocListCast(user.sharingDoc[storage])) !== -1 && Doc.RemoveDocFromList(user.sharingDoc, storage, doc); // remove the doc only if it is in the list
- });
+ DocListCastAsync(group.docsShared).then(dl => dl?.forEach(doc => {
+ Doc.RemoveDocFromList(user.sharingDoc, storage, doc);
+ }));
}
}
diff --git a/src/fields/util.ts b/src/fields/util.ts
index 1e6707a9a..791b98b83 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -4,7 +4,7 @@ import { SerializationHelper } from "../client/util/SerializationHelper";
import { ProxyField, PrefetchProxy } from "./Proxy";
import { RefField } from "./RefField";
import { ObjectField } from "./ObjectField";
-import { action, trace, observable, reaction } from "mobx";
+import { action, trace, observable, reaction, computed } from "mobx";
import { Parent, OnUpdate, Update, Id, SelfProxy, Self, HandleUpdate, ToString, ToScriptString } from "./FieldSymbols";
import { DocServer } from "../client/DocServer";
import { ComputedField } from "./ScriptField";
@@ -24,19 +24,28 @@ export function TraceMobx() {
// the list of groups that the current user is a member of
export class UserGroups {
- @observable static Current: string[];
- @action static setCurrentUserGroups(groupList: List<Doc>) {
- reaction(() => groupList,
- groupList => {
- UserGroups.Current = [
+ static computing = false;
+ static cachedGroups: string[] = [];
+ static globalGroupDoc: Doc | undefined;
+ static get Current() {
+ if (!Doc.UserDoc() || UserGroups.computing) return UserGroups.cachedGroups;
+ UserGroups.computing = true;
+ if (!UserGroups.globalGroupDoc) UserGroups.globalGroupDoc = Doc.UserDoc().globalGroupDatabase as Doc;
+ if (UserGroups.globalGroupDoc) {
+ const dbgroups = DocListCast(UserGroups.globalGroupDoc.data);
+ if (dbgroups.length !== UserGroups.cachedGroups.length - 1) {
+ UserGroups.cachedGroups = [
"Public",
- ...(groupList as List<Doc>).
+ ...dbgroups?.
filter(group => group instanceof Doc).
map(group => group as Doc).
filter(group => JSON.parse(StrCast(group.members))?.includes(Doc.CurrentUserEmail)).
map(group => StrCast(group.title))
];
- }, { fireImmediately: true });
+ }
+ }
+ UserGroups.computing = false;
+ return UserGroups.cachedGroups;
}
}
@@ -174,7 +183,6 @@ export enum SharingPermissions {
*/
export function GetEffectiveAcl(target: any, in_prop?: string | symbol | number, user?: string): symbol {
if (!target) return AclPrivate;
- if (target[Id] === "groupdbProto" || target[Id]?.startsWith("GROUP:")) return AclAdmin;
// all changes received fromt the server must be processed as Admin
if (in_prop === UpdatingFromServer || target[UpdatingFromServer]) return AclAdmin;