Files
outline/server/queues/processors/NotificationsProcessor.ts
Claude f5acd9c72b feat: Document verification and freshness tracking
Adds a verification lifecycle to documents, rebuilt on top of the new
main history. A user with admin-level access to a document (document
admin membership or team admin) can mark it as verified, vouching that
its content is accurate. Verification carries an optional expiry
deadline derived from a re-verification interval resolved through a
document → collection → team preference inheritance chain.

- documents.verify / documents.unverify API endpoints, gated by new
  verify/unverify abilities
- the feature requires the new DocumentVerification plan entitlement,
  included in the Business and Enterprise plans, and remains limited to
  cloud hosting
- verificationInterval override on documents.update and a collection
  default on collections.update (team admin only), plus a team-wide
  default via the verificationInterval team preference
- daily VerificationExpirySweepTask emits idempotent
  documents.verification_expired events without mutating documents;
  expiry is derived from the materialized verificationExpiresAt deadline
- notification and email to the verifier when their verification lapses;
  suppressed when the verifier is deleted, suspended, or lost access
- verification state excluded from duplicates and public shares; the
  interval override is carried over when duplicating

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mb5McXaNbEDyyCZXPAdGAY
2026-11-21 17:34:44 +00:00

163 lines
5.5 KiB
TypeScript

import type {
AccessRequestEvent,
CollectionEvent,
RevisionEvent,
Event,
DocumentEvent,
CommentEvent,
CollectionUserEvent,
DocumentUserEvent,
DocumentGroupEvent,
CommentReactionEvent,
GroupUserEvent,
} from "@server/types";
import CollectionAddUserNotificationsTask from "../tasks/CollectionAddUserNotificationsTask";
import CollectionCreatedNotificationsTask from "../tasks/CollectionCreatedNotificationsTask";
import CommentCreatedNotificationsTask from "../tasks/CommentCreatedNotificationsTask";
import CommentUpdatedNotificationsTask from "../tasks/CommentUpdatedNotificationsTask";
import ReactionCreatedNotificationsTask from "../tasks/ReactionCreatedNotificationsTask";
import ReactionRemovedNotificationsTask from "../tasks/ReactionRemovedNotificationsTask";
import DocumentAccessRequestNotificationsTask from "../tasks/DocumentAccessRequestNotificationsTask";
import DocumentAddGroupNotificationsTask from "../tasks/DocumentAddGroupNotificationsTask";
import DocumentAddUserNotificationsTask from "../tasks/DocumentAddUserNotificationsTask";
import DocumentPublishedNotificationsTask from "../tasks/DocumentPublishedNotificationsTask";
import DocumentVerificationExpiredNotificationsTask from "../tasks/DocumentVerificationExpiredNotificationsTask";
import GroupUserNotificationsTask from "../tasks/GroupUserNotificationsTask";
import RevisionCreatedNotificationsTask from "../tasks/RevisionCreatedNotificationsTask";
import ShareSubscriptionNotificationsTask from "../tasks/ShareSubscriptionNotificationsTask";
import BaseProcessor from "./BaseProcessor";
export default class NotificationsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = [
"documents.publish",
"documents.add_user",
"documents.add_group",
"documents.verification_expired",
"access_requests.create",
"revisions.create",
"collections.create",
"collections.add_user",
"groups.add_user",
"groups.remove_user",
"comments.create",
"comments.update",
"comments.add_reaction",
"comments.remove_reaction",
];
async perform(event: Event) {
switch (event.name) {
case "documents.publish":
return this.documentPublished(event);
case "documents.add_user":
return this.documentAddUser(event);
case "documents.add_group":
return this.documentAddGroup(event);
case "documents.verification_expired":
return this.documentVerificationExpired(event);
case "access_requests.create":
return this.documentAccessRequest(event);
case "revisions.create":
return this.revisionCreated(event);
case "collections.create":
return this.collectionCreated(event);
case "collections.add_user":
return this.collectionAddUser(event);
case "groups.add_user":
case "groups.remove_user":
return this.groupUserChanged(event);
case "comments.create":
return this.commentCreated(event);
case "comments.update":
return this.commentUpdated(event);
case "comments.add_reaction":
return this.reactionCreated(event);
case "comments.remove_reaction":
return this.reactionRemoved(event);
default:
}
}
async documentPublished(event: DocumentEvent) {
// never send notifications when batch importing
if (event.name === "documents.publish" && event.data?.source === "import") {
return;
}
await new DocumentPublishedNotificationsTask().schedule(event);
}
async documentAddUser(event: DocumentUserEvent) {
if (!event.data?.isNew || event.userId === event.actorId) {
return;
}
await new DocumentAddUserNotificationsTask().schedule(event);
}
async documentAddGroup(event: DocumentGroupEvent) {
if (!event.data.isNew) {
return;
}
await new DocumentAddGroupNotificationsTask().schedule(event);
}
async documentAccessRequest(event: AccessRequestEvent) {
await new DocumentAccessRequestNotificationsTask().schedule(event);
}
async documentVerificationExpired(event: DocumentEvent) {
await new DocumentVerificationExpiredNotificationsTask().schedule(event);
}
async revisionCreated(event: RevisionEvent) {
await Promise.all([
new RevisionCreatedNotificationsTask().schedule(event),
new ShareSubscriptionNotificationsTask().schedule(event),
]);
}
async collectionCreated(event: CollectionEvent) {
// never send notifications when batch importing
if (
!!event.changes?.attributes.apiImportId ||
!!event.changes?.attributes.importId
) {
return;
}
await new CollectionCreatedNotificationsTask().schedule(event);
}
async collectionAddUser(event: CollectionUserEvent) {
if (!event.data?.isNew || event.userId === event.actorId) {
return;
}
await new CollectionAddUserNotificationsTask().schedule(event);
}
async groupUserChanged(event: GroupUserEvent) {
if (event.userId === event.actorId) {
return;
}
await new GroupUserNotificationsTask().schedule(event);
}
async commentCreated(event: CommentEvent) {
await new CommentCreatedNotificationsTask().schedule(event);
}
async commentUpdated(event: CommentEvent) {
await new CommentUpdatedNotificationsTask().schedule(event);
}
async reactionCreated(event: CommentReactionEvent) {
await new ReactionCreatedNotificationsTask().schedule(event);
}
async reactionRemoved(event: CommentReactionEvent) {
await new ReactionRemovedNotificationsTask().schedule(event);
}
}