diff --git a/app/client/models/AppModel.ts b/app/client/models/AppModel.ts index 3de1c9c6..0cceeeed 100644 --- a/app/client/models/AppModel.ts +++ b/app/client/models/AppModel.ts @@ -128,6 +128,7 @@ export interface AppModel { isOwnerOrEditor(): boolean; // If user is an owner or editor of this org /** Creates an computed observable to dismiss a popup or check if it was dismissed */ dismissedPopup(name: DismissedPopup): Observable; + switchUser(user: FullUser, org?: string): Promise; } export class TopAppModelImpl extends Disposable implements TopAppModel { @@ -402,6 +403,11 @@ export class AppModelImpl extends Disposable implements AppModel { return computed; } + public async switchUser(user: FullUser, org?: string) { + await this.api.setSessionActive(user.email, org); + this.lastVisitedOrgDomain.set(null); + } + private _updateLastVisitedOrgDomain({doc, org}: IGristUrlState, availableOrgs: Organization[]) { if ( !org || diff --git a/app/client/ui/AccountWidget.ts b/app/client/ui/AccountWidget.ts index 071c036f..f221c87b 100644 --- a/app/client/ui/AccountWidget.ts +++ b/app/client/ui/AccountWidget.ts @@ -174,7 +174,7 @@ export class AccountWidget extends Disposable { // Switch BrowserSession to use the given user for the currently loaded org. private async _switchAccount(user: FullUser) { - await this._appModel.api.setSessionActive(user.email); + await this._appModel.switchUser(user); if (urlState().state.get().doc) { // Document access level may have changed. // If it was not accessible but now is, we currently need to reload the page to get diff --git a/app/client/ui/AppHeader.ts b/app/client/ui/AppHeader.ts index fbcd9a39..43448789 100644 --- a/app/client/ui/AppHeader.ts +++ b/app/client/ui/AppHeader.ts @@ -92,8 +92,10 @@ export class AppHeader extends Disposable { } private _buildOrgLinkOrMenu() { - const {currentValidUser, isPersonal, isTemplatesSite} = this._appModel; - if (!currentValidUser && (isPersonal || isTemplatesSite)) { + const {currentValidUser, isTemplatesSite} = this._appModel; + const {deploymentType} = getGristConfig(); + if (deploymentType === 'saas' && !currentValidUser && isTemplatesSite) { + // When signed out and on the templates site (in SaaS Grist), link to the templates page. return cssOrgLink( cssOrgName(dom.text(this._appLogoOrgName), testId('dm-orgname')), {href: commonUrls.templates}, @@ -180,11 +182,11 @@ export class AppHeader extends Disposable { }): AppLogoOrgNameAndLink { const { currentValidUser, - isPersonal, isTemplatesSite, } = this._appModel; - if (!currentValidUser && (isPersonal || isTemplatesSite)) { - // When signed out and not on a team site, link to the templates site. + const {deploymentType} = getGristConfig(); + if (deploymentType === 'saas' && !currentValidUser && isTemplatesSite) { + // When signed out and on the templates site (in SaaS Grist), link to the templates page. return { name: t('Grist Templates'), link: { diff --git a/app/client/ui/WelcomeSitePicker.ts b/app/client/ui/WelcomeSitePicker.ts index 9d896c3c..07b648b3 100644 --- a/app/client/ui/WelcomeSitePicker.ts +++ b/app/client/ui/WelcomeSitePicker.ts @@ -63,7 +63,7 @@ async function switchToPersonalUrl(ev: MouseEvent, appModel: AppModel, org: stri if (ev.shiftKey || ev.metaKey || ev.ctrlKey || ev.altKey) { return; } ev.preventDefault(); // Set the active session for the given org, then load its home page. - await appModel.api.setSessionActive(user.email, org); + await appModel.switchUser(user, org); window.location.assign(urlState().makeUrl({org})); } diff --git a/test/nbrowser/Fork.ts b/test/nbrowser/Fork.ts index ae884060..21356c95 100644 --- a/test/nbrowser/Fork.ts +++ b/test/nbrowser/Fork.ts @@ -93,7 +93,7 @@ describe("Fork", function() { it(`can create an ${content} unsaved document when ${mode}`, async function() { let visitedSites: string[]; if (mode === 'anonymous') { - visitedSites = ['Grist Templates']; + visitedSites = ['@Guest']; await personal.anon.login(); } else { visitedSites = ['Test Grist', `@${personal.name}`];