(core) Adding a flag for the UI to check if emails are enabled

Summary:
Front-end code can now test if emails are enabled
and hide some parts of UI based on it.

Test Plan:
Only secondery text was hidden on add users dialog.
Tested manually.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: georgegevoian

Differential Revision: https://phab.getgrist.com/D4221
pull/936/head
Jarosław Sadziński 2 months ago
parent c87d835533
commit 03ead0d1ca

@ -16,6 +16,7 @@ import {
cssMemberText,
} from "app/client/ui/UserItem";
import {createUserImage, cssUserImage} from "app/client/ui/UserImage";
import {getGristConfig} from 'app/common/urlUtils';
import {Computed, computed, dom, DomElementArg, Holder, IDisposableOwner, Observable, styled} from "grainjs";
import {cssMenuItem} from "popweasel";
@ -111,10 +112,9 @@ export function buildACMemberEmail(
)),
cssMemberText(
cssMemberPrimaryPlus(t("Invite new member")),
cssMemberSecondaryPlus(
// dom.text(use => `We'll email an invite to ${use(emailObs)}`)
dom.text(use => t("We'll email an invite to {{email}}", {email: use(emailObs)})) // TODO i18next
)
getGristConfig().notifierEnabled ? cssMemberSecondaryPlus(
dom.text(use => t("We'll email an invite to {{email}}", {email: use(emailObs)}))
) : null,
),
testId("um-add-email")
)

@ -786,6 +786,9 @@ export interface GristLoadConfig {
canCloseAccount?: boolean;
experimentalPlugins?: boolean;
// If backend has an email service for sending notifications.
notifierEnabled?: boolean;
}
export const Features = StringUnion(

@ -47,7 +47,7 @@ import {initGristSessions, SessionStore} from 'app/server/lib/gristSessions';
import {HostedStorageManager} from 'app/server/lib/HostedStorageManager';
import {IBilling} from 'app/server/lib/IBilling';
import {IDocStorageManager} from 'app/server/lib/IDocStorageManager';
import {INotifier} from 'app/server/lib/INotifier';
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';
@ -384,7 +384,7 @@ export class FlexServer implements GristServer {
}
public hasNotifier(): boolean {
return Boolean(this._notifier);
return Boolean(this._notifier) && this._notifier !== EmptyNotifier;
}
public getNotifier(): INotifier {

@ -52,6 +52,7 @@ export interface GristServer {
getHomeDBManager(): HomeDBManager;
getStorageManager(): IDocStorageManager;
getTelemetry(): ITelemetry;
hasNotifier(): boolean;
getNotifier(): INotifier;
getDocTemplate(): Promise<DocTemplate>;
getTag(): string;
@ -142,6 +143,7 @@ export function createDummyGristServer(): GristServer {
getStorageManager() { throw new Error('no storage manager'); },
getTelemetry() { return createDummyTelemetry(); },
getNotifier() { throw new Error('no notifier'); },
hasNotifier() { return false; },
getDocTemplate() { throw new Error('no doc template'); },
getTag() { return 'tag'; },
sendAppPage() { return Promise.resolve(); },

@ -5,7 +5,7 @@ import {HomeDBManager} from 'app/gen-server/lib/HomeDBManager';
import {ExternalStorage} from 'app/server/lib/ExternalStorage';
import {createDummyTelemetry, GristServer} from 'app/server/lib/GristServer';
import {IBilling} from 'app/server/lib/IBilling';
import {INotifier} from 'app/server/lib/INotifier';
import {EmptyNotifier, INotifier} from 'app/server/lib/INotifier';
import {InstallAdmin, SimpleInstallAdmin} from 'app/server/lib/InstallAdmin';
import {ISandbox, ISandboxCreationOptions} from 'app/server/lib/ISandbox';
import {IShell} from 'app/server/lib/IShell';
@ -99,11 +99,7 @@ export function makeSimpleCreator(opts: {
};
},
Notifier(dbManager, gristConfig) {
return notifier?.create(dbManager, gristConfig) ?? {
get testPending() { return false; },
async deleteUser() { /* do nothing */ },
testSetSendMessageCallback() { return undefined; },
};
return notifier?.create(dbManager, gristConfig) ?? EmptyNotifier;
},
ExternalStorage(purpose, extraPrefix) {
for (const s of storage || []) {

@ -10,3 +10,12 @@ export interface INotifier {
// Return undefined if no notification system is available.
testSetSendMessageCallback(op: (body: SendGridMail, description: string) => Promise<void>): SendGridConfig|undefined;
}
/**
* A notifier that does nothing. Used when no email notifications are configured.
*/
export const EmptyNotifier: INotifier = {
get testPending() { return false; },
async deleteUser() { /* do nothing */ },
testSetSendMessageCallback() { return undefined; },
} as const;

@ -97,6 +97,7 @@ export function makeGristConfig(options: MakeGristConfigOptions): GristLoadConfi
templateOrg: getTemplateOrg(),
canCloseAccount: isAffirmative(process.env.GRIST_ACCOUNT_CLOSE),
experimentalPlugins: isAffirmative(process.env.GRIST_EXPERIMENTAL_PLUGINS),
notifierEnabled: server?.hasNotifier(),
...extra,
};
}

Loading…
Cancel
Save