mirror of
https://github.com/outline/outline.git
synced 2026-12-06 19:22:29 +03:00
fix: Allow every mention notification to be turned off and unsubscribed
- The Mentioned and Group mentions settings now control both the document and comment event types. - Mention, share, collection invite, and access request emails now have an unsubscribe link and List-Unsubscribe header.
This commit is contained in:
8 files changed
+247
-32
No files matched your search
@@ -1,11 +1,13 @@
|
||||
import * as React from "react";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { CollectionPermission, NotificationEventType } from "@shared/types";
|
||||
import { Collection, UserMembership } from "@server/models";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import type { EmailProps } from "./BaseEmail";
|
||||
import BaseEmail, { EmailMessageCategory } from "./BaseEmail";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
import EmailTemplate from "./components/EmailLayout";
|
||||
import Footer from "./components/Footer";
|
||||
import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
@@ -53,6 +55,13 @@ export default class CollectionSharedEmail extends BaseEmail<
|
||||
return { collection, membership };
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.AddUserToCollection
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ actorName, collection }: Props) {
|
||||
return this.t(
|
||||
"{{ actorName }} invited you to the “{{ collectionName }}” collection",
|
||||
@@ -111,6 +120,11 @@ ${this.t("View Collection")}: ${teamUrl}${collection.path}
|
||||
<Button href={collectionUrl}>{this.t("View Collection")}</Button>
|
||||
</p>
|
||||
</Body>
|
||||
|
||||
<Footer
|
||||
unsubscribeUrl={this.unsubscribeUrl(props)}
|
||||
unsubscribeText={this.t("Unsubscribe from these emails")}
|
||||
/>
|
||||
</EmailTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import * as React from "react";
|
||||
import { NotificationEventType } from "@shared/types";
|
||||
import { Document, User } from "@server/models";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import type { EmailProps } from "./BaseEmail";
|
||||
import BaseEmail, { EmailMessageCategory } from "./BaseEmail";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
import EmailTemplate from "./components/EmailLayout";
|
||||
import Footer from "./components/Footer";
|
||||
import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
type InputProps = EmailProps & {
|
||||
userId: string;
|
||||
documentId: string;
|
||||
actorId: string;
|
||||
teamUrl: string;
|
||||
@@ -46,6 +50,13 @@ export default class DocumentAccessRequestEmail extends BaseEmail<
|
||||
return { document, actor };
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.RequestDocumentAccess
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ actor, document }: Props) {
|
||||
return `${actor.name} is requesting access to “${document.displayTitle}”`;
|
||||
}
|
||||
@@ -88,6 +99,11 @@ Open the document to share it with them: ${teamUrl}${document.path}
|
||||
<Button href={documentUrl}>View Document</Button>
|
||||
</p>
|
||||
</Body>
|
||||
|
||||
<Footer
|
||||
unsubscribeUrl={this.unsubscribeUrl(props)}
|
||||
unsubscribeText={this.t("Unsubscribe from these emails")}
|
||||
/>
|
||||
</EmailTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { differenceBy } from "es-toolkit/compat";
|
||||
import * as React from "react";
|
||||
import { MentionType } from "@shared/types";
|
||||
import { MentionType, NotificationEventType } from "@shared/types";
|
||||
import { Document, Revision } from "@server/models";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
|
||||
import { can } from "@server/policies";
|
||||
import type { EmailProps } from "./BaseEmail";
|
||||
@@ -12,6 +13,7 @@ import Button from "./components/Button";
|
||||
import Diff from "./components/Diff";
|
||||
import EmailTemplate from "./components/EmailLayout";
|
||||
import EmptySpace from "./components/EmptySpace";
|
||||
import Footer from "./components/Footer";
|
||||
import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
@@ -92,6 +94,13 @@ export default class DocumentMentionedEmail extends BaseEmail<
|
||||
return { document, body };
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.MentionedInDocument
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ document }: Props) {
|
||||
return this.t(`Mentioned you in “{{ documentTitle }}”`, {
|
||||
documentTitle: document.displayTitle,
|
||||
@@ -157,6 +166,11 @@ ${this.t("Open Document")}: ${teamUrl}${document.url}
|
||||
<Button href={documentLink}>{this.t("Open Document")}</Button>
|
||||
</p>
|
||||
</Body>
|
||||
|
||||
<Footer
|
||||
unsubscribeUrl={this.unsubscribeUrl(props)}
|
||||
unsubscribeText={this.t("Unsubscribe from these emails")}
|
||||
/>
|
||||
</EmailTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import * as React from "react";
|
||||
import { DocumentPermission } from "@shared/types";
|
||||
import { DocumentPermission, NotificationEventType } from "@shared/types";
|
||||
import { Document, GroupMembership, UserMembership } from "@server/models";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import type { EmailProps } from "./BaseEmail";
|
||||
import BaseEmail, { EmailMessageCategory } from "./BaseEmail";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
import EmailTemplate from "./components/EmailLayout";
|
||||
import Footer from "./components/Footer";
|
||||
import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
@@ -56,6 +58,13 @@ export default class DocumentSharedEmail extends BaseEmail<
|
||||
return { document, membership };
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.AddUserToDocument
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ actorName, document }: Props) {
|
||||
return this.t(`{{ actorName }} shared “{{ documentTitle }}” with you`, {
|
||||
actorName,
|
||||
@@ -109,6 +118,11 @@ ${this.t("View Document")}: ${teamUrl}${document.path}
|
||||
<Button href={documentUrl}>{this.t("View Document")}</Button>
|
||||
</p>
|
||||
</Body>
|
||||
|
||||
<Footer
|
||||
unsubscribeUrl={this.unsubscribeUrl(props)}
|
||||
unsubscribeText={this.t("Unsubscribe from these emails")}
|
||||
/>
|
||||
</EmailTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { differenceBy } from "es-toolkit/compat";
|
||||
import * as React from "react";
|
||||
import { MentionType } from "@shared/types";
|
||||
import { MentionType, NotificationEventType } from "@shared/types";
|
||||
import { Document, Revision, Group } from "@server/models";
|
||||
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
|
||||
import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper";
|
||||
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
|
||||
import { can } from "@server/policies";
|
||||
import type { EmailProps } from "./BaseEmail";
|
||||
@@ -12,10 +13,12 @@ import Button from "./components/Button";
|
||||
import Diff from "./components/Diff";
|
||||
import EmailTemplate from "./components/EmailLayout";
|
||||
import EmptySpace from "./components/EmptySpace";
|
||||
import Footer from "./components/Footer";
|
||||
import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
type InputProps = EmailProps & {
|
||||
userId: string;
|
||||
documentId: string;
|
||||
revisionId: string | undefined;
|
||||
actorName: string;
|
||||
@@ -98,6 +101,13 @@ export default class GroupDocumentMentionedEmail extends BaseEmail<
|
||||
return { document, body, groupName: group.name };
|
||||
}
|
||||
|
||||
protected unsubscribeUrl({ userId }: InputProps) {
|
||||
return NotificationSettingsHelper.unsubscribeUrl(
|
||||
userId,
|
||||
NotificationEventType.GroupMentionedInDocument
|
||||
);
|
||||
}
|
||||
|
||||
protected subject({ document, groupName }: Props) {
|
||||
return this.t(
|
||||
`The {{ groupName }} group was mentioned in “{{ documentTitle }}”`,
|
||||
@@ -174,6 +184,11 @@ ${this.t("Open Document")}: ${teamUrl}${document.url}
|
||||
<Button href={documentLink}>{this.t("Open Document")}</Button>
|
||||
</p>
|
||||
</Body>
|
||||
|
||||
<Footer
|
||||
unsubscribeUrl={this.unsubscribeUrl(props)}
|
||||
unsubscribeText={this.t("Unsubscribe from these emails")}
|
||||
/>
|
||||
</EmailTemplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { CollectionPermission, DocumentPermission } from "@shared/types";
|
||||
import mailer from "@server/emails/mailer";
|
||||
import { UserMembership } from "@server/models";
|
||||
import {
|
||||
buildCollection,
|
||||
buildDocument,
|
||||
buildGroup,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import CollectionSharedEmail from "./CollectionSharedEmail";
|
||||
import DocumentAccessRequestEmail from "./DocumentAccessRequestEmail";
|
||||
import DocumentMentionedEmail from "./DocumentMentionedEmail";
|
||||
import DocumentSharedEmail from "./DocumentSharedEmail";
|
||||
import GroupDocumentMentionedEmail from "./GroupDocumentMentionedEmail";
|
||||
|
||||
const teamUrl = "https://example.outline.dev";
|
||||
|
||||
describe("notification emails", () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(mailer, "sendMail").mockResolvedValue();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const expectUnsubscribe = (eventType: string, userId: string) => {
|
||||
expect(mailer.sendMail).toHaveBeenCalledTimes(1);
|
||||
const options = vi.mocked(mailer.sendMail).mock.calls[0][0];
|
||||
expect(options.unsubscribeUrl).toContain(`userId=${userId}`);
|
||||
expect(options.unsubscribeUrl).toContain(`eventType=${eventType}`);
|
||||
};
|
||||
|
||||
it("should include an unsubscribe link in DocumentMentionedEmail", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({ teamId: user.teamId });
|
||||
|
||||
await new DocumentMentionedEmail({
|
||||
to: user.email,
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
revisionId: undefined,
|
||||
actorName: "Actor",
|
||||
teamUrl,
|
||||
}).send();
|
||||
|
||||
expectUnsubscribe("documents.mentioned", user.id);
|
||||
});
|
||||
|
||||
it("should include an unsubscribe link in GroupDocumentMentionedEmail", async () => {
|
||||
const user = await buildUser();
|
||||
const group = await buildGroup({ teamId: user.teamId });
|
||||
const document = await buildDocument({ teamId: user.teamId });
|
||||
|
||||
await new GroupDocumentMentionedEmail({
|
||||
to: user.email,
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
revisionId: undefined,
|
||||
groupId: group.id,
|
||||
actorName: "Actor",
|
||||
teamUrl,
|
||||
}).send();
|
||||
|
||||
expectUnsubscribe("documents.group_mentioned", user.id);
|
||||
});
|
||||
|
||||
it("should include an unsubscribe link in DocumentSharedEmail", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({ teamId: user.teamId });
|
||||
const membership = await UserMembership.create({
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
createdById: document.createdById,
|
||||
permission: DocumentPermission.Read,
|
||||
});
|
||||
|
||||
await new DocumentSharedEmail({
|
||||
to: user.email,
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
membershipId: membership.id,
|
||||
actorName: "Actor",
|
||||
teamUrl,
|
||||
}).send();
|
||||
|
||||
expectUnsubscribe("documents.add_user", user.id);
|
||||
});
|
||||
|
||||
it("should include an unsubscribe link in CollectionSharedEmail", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({ teamId: user.teamId });
|
||||
await UserMembership.create({
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
createdById: collection.createdById,
|
||||
permission: CollectionPermission.Read,
|
||||
});
|
||||
|
||||
await new CollectionSharedEmail({
|
||||
to: user.email,
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
actorName: "Actor",
|
||||
teamUrl,
|
||||
}).send();
|
||||
|
||||
expectUnsubscribe("collections.add_user", user.id);
|
||||
});
|
||||
|
||||
it("should include an unsubscribe link in DocumentAccessRequestEmail", async () => {
|
||||
const user = await buildUser();
|
||||
const actor = await buildUser({ teamId: user.teamId });
|
||||
const document = await buildDocument({ teamId: user.teamId });
|
||||
|
||||
await new DocumentAccessRequestEmail({
|
||||
to: user.email,
|
||||
userId: user.id,
|
||||
documentId: document.id,
|
||||
actorId: actor.id,
|
||||
teamUrl,
|
||||
}).send();
|
||||
|
||||
expectUnsubscribe("access_requests.create", user.id);
|
||||
});
|
||||
});
|
||||
@@ -94,6 +94,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
{
|
||||
to: notification.user.email,
|
||||
language: notification.user.language,
|
||||
userId: notification.userId,
|
||||
documentId: notification.documentId,
|
||||
revisionId: notification.revisionId,
|
||||
groupId: notification.groupId,
|
||||
@@ -215,6 +216,7 @@ export default class EmailsProcessor extends BaseProcessor {
|
||||
await new DocumentAccessRequestEmail(
|
||||
{
|
||||
to: notification.user.email,
|
||||
userId: notification.userId,
|
||||
documentId: notification.documentId,
|
||||
actorId: notification.actorId,
|
||||
teamUrl: notification.team.url,
|
||||
|
||||
Reference in new issue
Block a user