chore: Email + mailer refactor (#3342)
* Huge email refactor * fix: One rename too many * comments
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import fs from "fs";
|
||||
import invariant from "invariant";
|
||||
import ExportFailureEmail from "@server/emails/templates/ExportFailureEmail";
|
||||
import ExportSuccessEmail from "@server/emails/templates/ExportSuccessEmail";
|
||||
import Logger from "@server/logging/logger";
|
||||
import { FileOperation, Collection, Event, Team, User } from "@server/models";
|
||||
import EmailTask from "@server/queues/tasks/EmailTask";
|
||||
import { Event as TEvent } from "@server/types";
|
||||
import { uploadToS3FromBuffer } from "@server/utils/s3";
|
||||
import { archiveCollections } from "@server/utils/zip";
|
||||
@@ -88,21 +89,15 @@ export default class ExportsProcessor extends BaseProcessor {
|
||||
});
|
||||
|
||||
if (state === "error") {
|
||||
await EmailTask.schedule({
|
||||
type: "exportFailure",
|
||||
options: {
|
||||
to: user.email,
|
||||
teamUrl: team.url,
|
||||
},
|
||||
await ExportFailureEmail.schedule({
|
||||
to: user.email,
|
||||
teamUrl: team.url,
|
||||
});
|
||||
} else {
|
||||
await EmailTask.schedule({
|
||||
type: "exportSuccess",
|
||||
options: {
|
||||
to: user.email,
|
||||
id: fileOperation.id,
|
||||
teamUrl: team.url,
|
||||
},
|
||||
await ExportSuccessEmail.schedule({
|
||||
to: user.email,
|
||||
id: fileOperation.id,
|
||||
teamUrl: team.url,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import DocumentNotificationEmail from "@server/emails/templates/DocumentNotificationEmail";
|
||||
import { View, NotificationSetting } from "@server/models";
|
||||
import EmailTask from "@server/queues/tasks/EmailTask";
|
||||
import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { flushdb } from "@server/test/support";
|
||||
import NotificationsProcessor from "./NotificationsProcessor";
|
||||
|
||||
jest.mock("@server/queues/tasks/EmailTask");
|
||||
jest.mock("@server/emails/templates/DocumentNotificationEmail");
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
beforeEach(() => flushdb());
|
||||
@@ -39,7 +39,7 @@ describe("documents.publish", () => {
|
||||
},
|
||||
ip,
|
||||
});
|
||||
expect(EmailTask.schedule).not.toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should send a notification to other users in team", async () => {
|
||||
@@ -65,7 +65,7 @@ describe("documents.publish", () => {
|
||||
},
|
||||
ip,
|
||||
});
|
||||
expect(EmailTask.schedule).toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should not send a notification to users without collection access", async () => {
|
||||
@@ -95,7 +95,7 @@ describe("documents.publish", () => {
|
||||
},
|
||||
ip,
|
||||
});
|
||||
expect(EmailTask.schedule).not.toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("revisions.create", () => {
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
});
|
||||
expect(EmailTask.schedule).toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should not send a notification if viewed since update", async () => {
|
||||
@@ -143,7 +143,7 @@ describe("revisions.create", () => {
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
});
|
||||
expect(EmailTask.schedule).not.toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("should not send a notification to last editor", async () => {
|
||||
@@ -164,6 +164,6 @@ describe("revisions.create", () => {
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
});
|
||||
expect(EmailTask.schedule).not.toHaveBeenCalled();
|
||||
expect(DocumentNotificationEmail.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Op } from "sequelize";
|
||||
import CollectionNotificationEmail from "@server/emails/templates/CollectionNotificationEmail";
|
||||
import DocumentNotificationEmail from "@server/emails/templates/DocumentNotificationEmail";
|
||||
import Logger from "@server/logging/logger";
|
||||
import { APM } from "@server/logging/tracing";
|
||||
import {
|
||||
@@ -15,7 +17,6 @@ import {
|
||||
RevisionEvent,
|
||||
Event,
|
||||
} from "@server/types";
|
||||
import EmailTask from "../tasks/EmailTask";
|
||||
import BaseProcessor from "./BaseProcessor";
|
||||
|
||||
@APM.trace()
|
||||
@@ -123,17 +124,14 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
continue;
|
||||
}
|
||||
|
||||
await EmailTask.schedule({
|
||||
type: "documentNotification",
|
||||
options: {
|
||||
to: setting.user.email,
|
||||
eventName,
|
||||
documentId: document.id,
|
||||
teamUrl: team.url,
|
||||
actorName: document.updatedBy.name,
|
||||
collectionName: collection.name,
|
||||
unsubscribeUrl: setting.unsubscribeUrl,
|
||||
},
|
||||
await DocumentNotificationEmail.schedule({
|
||||
to: setting.user.email,
|
||||
eventName,
|
||||
documentId: document.id,
|
||||
teamUrl: team.url,
|
||||
actorName: document.updatedBy.name,
|
||||
collectionName: collection.name,
|
||||
unsubscribeUrl: setting.unsubscribeUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -177,14 +175,11 @@ export default class NotificationsProcessor extends BaseProcessor {
|
||||
continue;
|
||||
}
|
||||
|
||||
await EmailTask.schedule({
|
||||
type: "collectionNotification",
|
||||
options: {
|
||||
to: setting.user.email,
|
||||
eventName: "created",
|
||||
collectionId: collection.id,
|
||||
unsubscribeUrl: setting.unsubscribeUrl,
|
||||
},
|
||||
await CollectionNotificationEmail.schedule({
|
||||
to: setting.user.email,
|
||||
eventName: "created",
|
||||
collectionId: collection.id,
|
||||
unsubscribeUrl: setting.unsubscribeUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user