Skip to content

Commit

Permalink
Move login system into ICreate
Browse files Browse the repository at this point in the history
  • Loading branch information
SleepyLeslie committed Jul 18, 2024
1 parent 7f7b18f commit e5b47d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
11 changes: 0 additions & 11 deletions app/server/MergedServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<GristLoginSystem>;

// Invoked in addDoc if set. Grist Desktop uses this to override DocStorageManager's getPath function.
storageManagerDecorator?: (original: IDocStorageManager) => void;
}

export class MergedServer {
Expand All @@ -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();

Expand Down
11 changes: 3 additions & 8 deletions app/server/lib/FlexServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -182,14 +181,15 @@ export class FlexServer implements GristServer {
private _getSignUpRedirectUrl: (req: express.Request, target: URL) => Promise<string>;
private _getLogoutRedirectUrl: (req: express.Request, nextUrl: URL) => Promise<string>;
private _sendAppPage: (req: express.Request, resp: express.Response, options: ISendAppPageOptions) => Promise<void>;
private _getLoginSystem?: () => Promise<GristLoginSystem>;
private _getLoginSystem: () => Promise<GristLoginSystem>;
// Set once ready() is called
private _isReady: boolean = false;
private _updateManager: UpdateManager;
private _sandboxInfo: SandboxInfo;

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);
Expand Down Expand Up @@ -269,11 +269,6 @@ export class FlexServer implements GristServer {
});
}

// Allow overridding the login system.
public setLoginSystem(loginSystem: () => Promise<GristLoginSystem>) {
this._getLoginSystem = loginSystem;
}

public getHost(): string {
return `${this.host}:${this.getOwnPort()}`;
}
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion app/server/lib/ICreate.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,6 +47,8 @@ export interface ICreate {
getSqliteVariant?(): SqliteVariant;
getSandboxVariants?(): Record<string, SpawnFn>;

getLoginSystem(): Promise<GristLoginSystem>;

// Used by Grist Desktop to override the getPath function.
decorateDocStorageManager? (original: IDocStorageManager): void;
}
Expand Down Expand Up @@ -89,6 +92,7 @@ export function makeSimpleCreator(opts: {
getSqliteVariant?: () => SqliteVariant,
getSandboxVariants?: () => Record<string, SpawnFn>,
createInstallAdmin?: (dbManager: HomeDBManager) => Promise<InstallAdmin>,
getLoginSystem?: () => Promise<GristLoginSystem>,
decorateDocStorageManager?: (original: IDocStorageManager) => void,
}): ICreate {
const {deploymentType, sessionSecret, storage, notifier, billing, telemetry} = opts;
Expand Down Expand Up @@ -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,
};
}
6 changes: 0 additions & 6 deletions stubs/app/server/lib/logins.ts

This file was deleted.

0 comments on commit e5b47d6

Please sign in to comment.