From e5b47d6b71f9573d4caf8b585ad18ef58ab84fa3 Mon Sep 17 00:00:00 2001 From: "Leslie H." Date: Thu, 18 Jul 2024 13:23:48 -0400 Subject: [PATCH] Move login system into ICreate --- app/server/MergedServer.ts | 11 ----------- app/server/lib/FlexServer.ts | 11 +++-------- app/server/lib/ICreate.ts | 7 ++++++- stubs/app/server/lib/logins.ts | 6 ------ 4 files changed, 9 insertions(+), 26 deletions(-) delete mode 100644 stubs/app/server/lib/logins.ts diff --git a/app/server/MergedServer.ts b/app/server/MergedServer.ts index fc68775b6b..617668ffc0 100644 --- a/app/server/MergedServer.ts +++ b/app/server/MergedServer.ts @@ -6,10 +6,8 @@ */ import {FlexServer, FlexServerOptions} from 'app/server/lib/FlexServer'; -import {GristLoginSystem} from 'app/server/lib/GristServer'; import log from 'app/server/lib/log'; import {getGlobalConfig} from "app/server/lib/globalConfig"; -import {IDocStorageManager} from './lib/IDocStorageManager'; // Allowed server types. We'll start one or a combination based on the value of GRIST_SERVERS // environment variable. @@ -61,11 +59,6 @@ interface ServerOptions extends FlexServerOptions { // If set, documents saved to external storage such as s3 (default is to check environment variables, // which get set in various ways in dev/test entry points) externalStorage?: boolean; - - loginSystem?: () => Promise; - - // Invoked in addDoc if set. Grist Desktop uses this to override DocStorageManager's getPath function. - storageManagerDecorator?: (original: IDocStorageManager) => void; } export class MergedServer { @@ -81,10 +74,6 @@ export class MergedServer { ms.flexServer.setServesPlugins(false); } - if (ms._options.loginSystem) { - ms.flexServer.setLoginSystem(ms._options.loginSystem); - } - ms.flexServer.addCleanup(); ms.flexServer.setDirectory(); diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 950222b972..46dafa787a 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -52,7 +52,6 @@ import {IDocStorageManager} from 'app/server/lib/IDocStorageManager'; import {EmptyNotifier, INotifier} from 'app/server/lib/INotifier'; import {InstallAdmin} from 'app/server/lib/InstallAdmin'; import log from 'app/server/lib/log'; -import {getLoginSystem} from 'app/server/lib/logins'; import {IPermitStore} from 'app/server/lib/Permit'; import {getAppPathTo, getAppRoot, getInstanceRoot, getUnpackedAppRoot} from 'app/server/lib/places'; import {addPluginEndpoints, limitToPlugins} from 'app/server/lib/PluginEndpoint'; @@ -182,7 +181,7 @@ export class FlexServer implements GristServer { private _getSignUpRedirectUrl: (req: express.Request, target: URL) => Promise; private _getLogoutRedirectUrl: (req: express.Request, nextUrl: URL) => Promise; private _sendAppPage: (req: express.Request, resp: express.Response, options: ISendAppPageOptions) => Promise; - private _getLoginSystem?: () => Promise; + private _getLoginSystem: () => Promise; // Set once ready() is called private _isReady: boolean = false; private _updateManager: UpdateManager; @@ -190,6 +189,7 @@ export class FlexServer implements GristServer { constructor(public port: number, public name: string = 'flexServer', public readonly options: FlexServerOptions = {}) { + this._getLoginSystem = create.getLoginSystem; this.settings = options.settings; this.app = express(); this.app.set('port', port); @@ -269,11 +269,6 @@ export class FlexServer implements GristServer { }); } - // Allow overridding the login system. - public setLoginSystem(loginSystem: () => Promise) { - this._getLoginSystem = loginSystem; - } - public getHost(): string { return `${this.host}:${this.getOwnPort()}`; } @@ -1975,7 +1970,7 @@ export class FlexServer implements GristServer { } public resolveLoginSystem() { - return process.env.GRIST_TEST_LOGIN ? getTestLoginSystem() : (this._getLoginSystem?.() || getLoginSystem()); + return process.env.GRIST_TEST_LOGIN ? getTestLoginSystem() : (this._getLoginSystem() ); } public addUpdatesCheck() { diff --git a/app/server/lib/ICreate.ts b/app/server/lib/ICreate.ts index 0f5900dfb3..ff2237a0c5 100644 --- a/app/server/lib/ICreate.ts +++ b/app/server/lib/ICreate.ts @@ -1,9 +1,10 @@ import {GristDeploymentType} from 'app/common/gristUrls'; +import { getCoreLoginSystem } from "app/server/lib/coreLogins"; import {getThemeBackgroundSnippet} from 'app/common/Themes'; import {Document} from 'app/gen-server/entity/Document'; import {HomeDBManager} from 'app/gen-server/lib/homedb/HomeDBManager'; import {ExternalStorage} from 'app/server/lib/ExternalStorage'; -import {createDummyTelemetry, GristServer} from 'app/server/lib/GristServer'; +import {createDummyTelemetry, GristLoginSystem, GristServer} from 'app/server/lib/GristServer'; import {IBilling} from 'app/server/lib/IBilling'; import {EmptyNotifier, INotifier} from 'app/server/lib/INotifier'; import {InstallAdmin, SimpleInstallAdmin} from 'app/server/lib/InstallAdmin'; @@ -46,6 +47,8 @@ export interface ICreate { getSqliteVariant?(): SqliteVariant; getSandboxVariants?(): Record; + getLoginSystem(): Promise; + // Used by Grist Desktop to override the getPath function. decorateDocStorageManager? (original: IDocStorageManager): void; } @@ -89,6 +92,7 @@ export function makeSimpleCreator(opts: { getSqliteVariant?: () => SqliteVariant, getSandboxVariants?: () => Record, createInstallAdmin?: (dbManager: HomeDBManager) => Promise, + getLoginSystem?: () => Promise, decorateDocStorageManager?: (original: IDocStorageManager) => void, }): ICreate { const {deploymentType, sessionSecret, storage, notifier, billing, telemetry} = opts; @@ -164,6 +168,7 @@ export function makeSimpleCreator(opts: { getSqliteVariant: opts.getSqliteVariant, getSandboxVariants: opts.getSandboxVariants, createInstallAdmin: opts.createInstallAdmin || (async (dbManager) => new SimpleInstallAdmin(dbManager)), + getLoginSystem: opts.getLoginSystem || getCoreLoginSystem, decorateDocStorageManager: opts.decorateDocStorageManager, }; } diff --git a/stubs/app/server/lib/logins.ts b/stubs/app/server/lib/logins.ts deleted file mode 100644 index d038ebcb58..0000000000 --- a/stubs/app/server/lib/logins.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { getCoreLoginSystem } from "app/server/lib/coreLogins"; -import { GristLoginSystem } from "app/server/lib/GristServer"; - -export async function getLoginSystem(): Promise { - return getCoreLoginSystem(); -}