Remove NotificationSettings table (#5036

* helper

* Add script to move notification settings

* wip, removal of NotificationSettings

* event name

* iteration

* test

* test

* Remove last of NotificationSettings model

* refactor

* More fixes

* snapshots

* Change emails to class instances for type safety

* test

* docs

* Update migration for self-hosted

* tsc
This commit is contained in:
Tom Moor
2023-03-18 09:32:41 -04:00
committed by GitHub
parent 41f97b0563
commit 45831e9469
58 changed files with 972 additions and 711 deletions

View File

@@ -20,7 +20,7 @@ describe("email", () => {
});
it("should respond with redirect location when user is SSO enabled", async () => {
const spy = jest.spyOn(WelcomeEmail, "schedule");
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
const user = await buildUser();
const res = await server.post("/auth/email", {
body: {
@@ -35,7 +35,7 @@ describe("email", () => {
});
it("should respond with success and email to be sent when user has SSO but disabled", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
const team = await buildTeam({
subdomain: "example",
});
@@ -76,7 +76,7 @@ describe("email", () => {
env.DEPLOYMENT = "hosted";
const user = await buildUser();
const spy = jest.spyOn(WelcomeEmail, "schedule");
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
await buildTeam({
subdomain: "example",
});
@@ -97,7 +97,7 @@ describe("email", () => {
});
it("should respond with success and email to be sent when user is not SSO enabled", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
const team = await buildTeam({
subdomain: "example",
});
@@ -120,7 +120,7 @@ describe("email", () => {
});
it("should respond with success regardless of whether successful to prevent crawling email logins", async () => {
const spy = jest.spyOn(WelcomeEmail, "schedule");
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
await buildTeam({
subdomain: "example",
});
@@ -140,7 +140,7 @@ describe("email", () => {
});
describe("with multiple users matching email", () => {
it("should default to current subdomain with SSO", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
env.URL = sharedEnv.URL = "http://localoutline.com";
env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true;
const email = "sso-user@example.org";
@@ -170,7 +170,7 @@ describe("email", () => {
});
it("should default to current subdomain with guest email", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
env.URL = sharedEnv.URL = "http://localoutline.com";
env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true;
const email = "guest-user@example.org";
@@ -200,7 +200,7 @@ describe("email", () => {
});
it("should default to custom domain with SSO", async () => {
const spy = jest.spyOn(WelcomeEmail, "schedule");
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
const email = "sso-user-2@example.org";
const team = await buildTeam({
domain: "docs.mycompany.com",
@@ -228,7 +228,7 @@ describe("email", () => {
});
it("should default to custom domain with guest email", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
const email = "guest-user-2@example.org";
const team = await buildTeam({
domain: "docs.mycompany.com",

View File

@@ -1,5 +1,5 @@
import Router from "koa-router";
import { Client } from "@shared/types";
import { Client, NotificationEventType } from "@shared/types";
import { parseDomain } from "@shared/utils/domains";
import InviteAcceptedEmail from "@server/emails/templates/InviteAcceptedEmail";
import SigninEmail from "@server/emails/templates/SigninEmail";
@@ -67,12 +67,13 @@ router.post(
}
// send email to users email address with a short-lived token
await SigninEmail.schedule({
await new SigninEmail({
to: user.email,
token: user.getEmailSigninToken(),
teamUrl: team.url,
client: client === Client.Desktop ? Client.Desktop : Client.Web,
});
}).schedule();
user.lastSigninEmailSentAt = new Date();
await user.save();
@@ -105,19 +106,19 @@ router.get("email.callback", async (ctx) => {
}
if (user.isInvited) {
await WelcomeEmail.schedule({
await new WelcomeEmail({
to: user.email,
teamUrl: user.team.url,
});
}).schedule();
const inviter = await user.$get("invitedBy");
if (inviter) {
await InviteAcceptedEmail.schedule({
if (inviter?.subscribedToEventType(NotificationEventType.InviteAccepted)) {
await new InviteAcceptedEmail({
to: inviter.email,
inviterId: inviter.id,
invitedName: user.name,
teamUrl: user.team.url,
});
}).schedule();
}
}