Files
outline/server/queues/tasks/DocumentVerificationExpiredNotificationsTask.ts
T
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

55 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NotificationEventType } from "@shared/types";
import { Document, Notification, User } from "@server/models";
import type { DocumentEvent } from "@server/types";
import { canUserAccessDocument } from "@server/utils/permissions";
import { BaseTask, TaskPriority } from "./base/BaseTask";
/**
* Notifies the verifier of a document that their verification has expired.
* The verifier is the only candidate recipient – when they have been removed,
* suspended, or have lost access to the document no notification is sent at
* all, the audit event alone records the expiry.
*/
export default class DocumentVerificationExpiredNotificationsTask extends BaseTask<DocumentEvent> {
public async perform(event: DocumentEvent) {
const document = await Document.findByPk(event.documentId);
if (!document || !document.verifiedAt || !document.verifiedById) {
return;
}
// ignore stale events – the document was re-verified with a new deadline
// after this event was emitted.
if (
event.name === "documents.verification_expired" &&
document.verificationExpiresAt?.toISOString() !== event.data.expiresAt
) {
return;
}
const recipient = await User.findByPk(document.verifiedById);
if (
!recipient ||
recipient.isSuspended ||
!recipient.subscribedToEventType(
NotificationEventType.VerificationExpired
) ||
!(await canUserAccessDocument(recipient, document.id))
) {
return;
}
await Notification.create({
event: NotificationEventType.VerificationExpired,
userId: recipient.id,
teamId: document.teamId,
documentId: document.id,
});
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}