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:
Tom Moor committed 2026-10-19 09:21:20 -04:00
1 parent 2f68f32b40
commit c2426eb40c
8 files changed
+247 -32

No files matched your search

+42 -28
View File
@@ -36,7 +36,7 @@ function Notifications() {
const options = [
{
event: NotificationEventType.PublishDocument,
events: [NotificationEventType.PublishDocument],
icon: <PublishIcon />,
title: t("Document published"),
description: t(
@@ -44,7 +44,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.UpdateDocument,
events: [NotificationEventType.UpdateDocument],
icon: <EditIcon />,
title: t("Document updated"),
description: t(
@@ -52,7 +52,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.CreateComment,
events: [NotificationEventType.CreateComment],
icon: <CommentIcon />,
title: t("Comment posted"),
description: t(
@@ -60,7 +60,10 @@ function Notifications() {
),
},
{
event: NotificationEventType.MentionedInComment,
events: [
NotificationEventType.MentionedInComment,
NotificationEventType.MentionedInDocument,
],
icon: <EmailIcon />,
title: t("Mentioned"),
description: t(
@@ -68,7 +71,10 @@ function Notifications() {
),
},
{
event: NotificationEventType.GroupMentionedInDocument,
events: [
NotificationEventType.GroupMentionedInDocument,
NotificationEventType.GroupMentionedInComment,
],
icon: <GroupIcon />,
title: t("Group mentions"),
description: t(
@@ -76,7 +82,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.ResolveComment,
events: [NotificationEventType.ResolveComment],
icon: <DoneIcon />,
title: t("Resolved"),
description: t(
@@ -84,7 +90,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.ReactionsCreate,
events: [NotificationEventType.ReactionsCreate],
icon: <SmileyIcon />,
title: t("Reaction added"),
description: t(
@@ -92,7 +98,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.CreateCollection,
events: [NotificationEventType.CreateCollection],
icon: <CollectionIcon />,
title: t("Collection created"),
description: t(
@@ -100,7 +106,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.InviteAccepted,
events: [NotificationEventType.InviteAccepted],
icon: <UserIcon />,
title: t("Invite accepted"),
description: t(
@@ -108,7 +114,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.AddUserToDocument,
events: [NotificationEventType.AddUserToDocument],
icon: <DocumentIcon />,
title: t("Invited to document"),
description: t(
@@ -116,7 +122,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.AddUserToCollection,
events: [NotificationEventType.AddUserToCollection],
icon: <CollectionIcon />,
title: t("Invited to collection"),
description: t(
@@ -124,7 +130,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.AddUserToGroup,
events: [NotificationEventType.AddUserToGroup],
icon: <GroupIcon />,
title: t("Group membership"),
description: t(
@@ -132,7 +138,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.ExportCompleted,
events: [NotificationEventType.ExportCompleted],
icon: <CheckboxIcon checked />,
title: t("Export completed"),
description: t(
@@ -140,7 +146,7 @@ function Notifications() {
),
},
{
event: NotificationEventType.RequestDocumentAccess,
events: [NotificationEventType.RequestDocumentAccess],
icon: <CheckboxIcon checked />,
title: t("Document access requested"),
description: t(
@@ -150,14 +156,14 @@ function Notifications() {
{
visible: isCloudHosted,
icon: <AcademicCapIcon />,
event: NotificationEventType.Onboarding,
events: [NotificationEventType.Onboarding],
title: t("Getting started"),
description: t("Tips on getting started with features and functionality"),
},
{
visible: isCloudHosted,
icon: <StarredIcon />,
event: NotificationEventType.Features,
events: [NotificationEventType.Features],
title: t("New features"),
description: t("Receive an email when new features of note are added"),
},
@@ -170,8 +176,11 @@ function Notifications() {
}, 500);
const handleChange = React.useCallback(
(eventType: NotificationEventType) => async (checked: boolean) => {
await user.setNotificationEventType(eventType, checked);
(eventTypes: NotificationEventType[]) => async (checked: boolean) => {
// Sequential, as each request saves the full settings object.
for (const eventType of eventTypes) {
await user.setNotificationEventType(eventType, checked);
}
showSuccessMessage();
},
[user, showSuccessMessage]
@@ -182,7 +191,9 @@ function Notifications() {
runInAction(() => {
const updated = { ...user.notificationSettings };
for (const option of visibleOptions) {
updated[option.event] = checked;
for (const eventType of option.events) {
updated[eventType] = checked;
}
}
user.notificationSettings = updated;
});
@@ -197,7 +208,7 @@ function Notifications() {
);
const allEnabled = visibleOptions.every((o) =>
user.subscribedToEventType(o.event)
o.events.every((eventType) => user.subscribedToEventType(eventType))
);
const showSuccessNotice = window.location.search === "?success";
@@ -231,14 +242,17 @@ function Notifications() {
</SettingRow>
{options.map((option) => {
const setting = user.subscribedToEventType(option.event);
const [name] = option.events;
const checked = option.events.every((eventType) =>
user.subscribedToEventType(eventType)
);
return (
<SettingRow
key={option.event}
key={name}
visible={option.visible}
label={option.title}
name={option.event}
name={name}
description={
<Text size="small" type="secondary">
{option.description}
@@ -247,11 +261,11 @@ function Notifications() {
compact
>
<Switch
key={option.event}
id={option.event}
name={option.event}
checked={!!setting}
onChange={handleChange(option.event)}
key={name}
id={name}
name={name}
checked={checked}
onChange={handleChange(option.events)}
/>
</SettingRow>
);
@@ -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,