(core) Send emails when 2FA settings are updated

Summary: When user 2FA status is changed, we now send out emails via SendGrid.

Test Plan: Server tests.

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: alexmojaki

Differential Revision: https://phab.getgrist.com/D3280
This commit is contained in:
George Gevoian 2022-02-23 16:27:16 -08:00
parent 8f1889d2d7
commit ff4e5d2769
3 changed files with 25 additions and 2 deletions

View File

@ -35,6 +35,7 @@ import {makeId} from 'app/server/lib/idUtils';
import * as log from 'app/server/lib/log';
import {Permit} from 'app/server/lib/Permit';
import {WebHookSecret} from "app/server/lib/Triggers";
import {StringUnion} from 'app/common/StringUnion';
import {EventEmitter} from 'events';
import flatten = require('lodash/flatten');
import pick = require('lodash/pick');
@ -48,6 +49,17 @@ import * as uuidv4 from "uuid/v4";
// fixed. See https://github.com/typeorm/typeorm/issues/1884#issuecomment-380767213
applyPatch();
export const NotifierEvents = StringUnion(
'addUser',
'userChange',
'firstLogin',
'addBillingManager',
'teamCreator',
'trialPeriodEndingSoon',
);
export type NotifierEvent = typeof NotifierEvents.type;
// Nominal email address of a user who can view anything (for thumbnails).
export const PREVIEWER_EMAIL = 'thumbnail@getgrist.com';
@ -190,6 +202,10 @@ export class HomeDBManager extends EventEmitter {
private _docAuthCache = new MapWithTTL<string, Promise<DocAuthResult>>(DOC_AUTH_CACHE_TTL);
public emit(event: NotifierEvent, ...args: any[]): boolean {
return super.emit(event, ...args);
}
/**
* Five aclRules, each with one group (with the names 'owners', 'editors', 'viewers',
* 'guests', and 'members') are created by default on every new entity (Organization,

View File

@ -99,7 +99,6 @@ export class FlexServer implements GristServer {
public host: string;
public tag: string;
public info = new Array<[string, any]>();
public notifier: INotifier;
public usage: Usage;
public housekeeper: Housekeeper;
public server: http.Server;
@ -123,6 +122,7 @@ export class FlexServer implements GristServer {
private _storageManager: IDocStorageManager;
private _docWorkerMap: IDocWorkerMap;
private _widgetRepository: IWidgetRepository;
private _notifier: INotifier;
private _internalPermitStore: IPermitStore; // store for permits that stay within our servers
private _externalPermitStore: IPermitStore; // store for permits that pass through outside servers
private _disabled: boolean = false;
@ -286,6 +286,11 @@ export class FlexServer implements GristServer {
return this._widgetRepository;
}
public getNotifier(): INotifier {
if (!this._notifier) { throw new Error('no notifier available'); }
return this._notifier;
}
public addLogging() {
if (this._check('logging')) { return; }
if (process.env.GRIST_LOG_SKIP_HTTP) { return; }
@ -1254,7 +1259,7 @@ export class FlexServer implements GristServer {
// and all that is needed is a refactor to pass that info along. But there is also the
// case of notification(s) from stripe. May need to associate a preferred base domain
// with org/user and persist that?
this.notifier = this.create.Notifier(this._dbManager, this);
this._notifier = this.create.Notifier(this._dbManager, this);
}
public getGristConfig(): GristLoadConfig {

View File

@ -9,6 +9,7 @@ import * as Comm from 'app/server/lib/Comm';
import { Hosts } from 'app/server/lib/extractOrg';
import { ICreate } from 'app/server/lib/ICreate';
import { IDocStorageManager } from 'app/server/lib/IDocStorageManager';
import { INotifier } from 'app/server/lib/INotifier';
import { IPermitStore } from 'app/server/lib/Permit';
import { Sessions } from 'app/server/lib/Sessions';
import * as express from 'express';
@ -34,6 +35,7 @@ export interface GristServer {
getHosts(): Hosts;
getHomeDBManager(): HomeDBManager;
getStorageManager(): IDocStorageManager;
getNotifier(): INotifier;
}
export interface GristLoginSystem {