diff --git a/app/client/models/UserManagerModel.ts b/app/client/models/UserManagerModel.ts index 62f16dc2..5cf05764 100644 --- a/app/client/models/UserManagerModel.ts +++ b/app/client/models/UserManagerModel.ts @@ -1,3 +1,4 @@ +import {GristDoc} from 'app/client/components/GristDoc'; import {AppModel} from 'app/client/models/AppModel'; import {DocPageModel} from 'app/client/models/DocPageModel'; import {reportWarning} from 'app/client/models/errors'; @@ -25,6 +26,8 @@ export interface UserManagerModel { isOrg: boolean; // Indicates if the UserManager is for an org annotations: Observable; // More information about shares, keyed by email. + gristDoc: GristDoc|null; // Populated if there is an open document. + // Resets all unsaved changes reset(): void; // Recreate annotations, factoring in any changes on the back-end. @@ -119,6 +122,8 @@ export class UserManagerModelImpl extends Disposable implements UserManagerModel public isOrg: boolean = this.resourceType === 'organization'; + public gristDoc: GristDoc|null; + // Checks if any members were added/removed/changed, if the max inherited role changed or if the // anonymous access setting changed to enable the confirm button to write changes to the server. public readonly isAnythingChanged: Computed = this.autoDispose(computed((use) => { @@ -142,6 +147,7 @@ export class UserManagerModelImpl extends Disposable implements UserManagerModel } ) { super(); + this.gristDoc = this._options.docPageModel?.gristDoc.get() ?? null; if (this._options.appModel) { const features = this._options.appModel.currentFeatures; this._shareAnnotator = new ShareAnnotator(features, initData); @@ -250,8 +256,7 @@ export class UserManagerModelImpl extends Disposable implements UserManagerModel // Loop through the members and update the delta. for (const m of members) { let access = m.access.get(); - if (m === this.publicMember && access === roles.EDITOR && - this._options.docPageModel?.gristDoc.get()?.hasGranularAccessRules()) { + if (m === this.publicMember && access === roles.EDITOR && this.gristDoc?.hasGranularAccessRules()) { access = roles.VIEWER; if (!options?.silent) { reportWarning('Public "Editor" access is incompatible with Access Rules. Reduced to "Viewer".'); diff --git a/app/client/ui/UserManager.ts b/app/client/ui/UserManager.ts index 2e61064c..e1a08997 100644 --- a/app/client/ui/UserManager.ts +++ b/app/client/ui/UserManager.ts @@ -121,13 +121,16 @@ export function showUserManagerModal(userApi: UserAPI, options: IUserManagerOpti dom.on('click', () => ctl.close()), testId('um-cancel') ), - cssAccessLink({href: urlState().makeUrl({docPage: 'acl'})}, - dom.text(use => (use(modelObs) && use(use(modelObs)!.isAnythingChanged)) ? 'Save & ' : ''), - 'Open Access Rules', - dom.on('click', (ev) => { - ev.preventDefault(); - return onConfirm(ctl).then(() => urlState().pushUrl({docPage: 'acl'})); - }), + dom.maybe(use => use(modelObs)?.resourceType === 'document' && use(modelObs)?.gristDoc, () => + cssAccessLink({href: urlState().makeUrl({docPage: 'acl'})}, + dom.text(use => (use(modelObs) && use(use(modelObs)!.isAnythingChanged)) ? 'Save & ' : ''), + 'Open Access Rules', + dom.on('click', (ev) => { + ev.preventDefault(); + return onConfirm(ctl).then(() => urlState().pushUrl({docPage: 'acl'})); + }), + testId('um-open-access-rules') + ) ), testId('um-buttons'), )