mirror of
https://github.com/outline/outline.git
synced 2026-11-29 00:29:36 +03:00
Adds a verification lifecycle to documents. 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 - 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 - verificationStatus filter (verified/unverified/expired/expiring) on documents.list - 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; presenter exposes verifiedAt/verifiedById/verificationExpiresAt/ verificationInterval and a derived editedSinceVerification flag Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mb5McXaNbEDyyCZXPAdGAY
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
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,
|
||
};
|
||
}
|
||
}
|