mirror of
https://github.com/outline/outline.git
synced 2026-12-04 10:24:43 +03:00
- add a partial index on verificationExpiresAt alone; the expiry sweep scans by deadline across all teams, which the team-prefixed index cannot serve - broadcast documents.verify and documents.unverify over WebSockets as a document update so open clients merge the changed verification fields without a reload - render a readable in-app notification for an expired verification, subject-first with a warning icon, instead of the raw event name and an unknown actor - skip the expiry notification when the team no longer holds the DocumentVerification entitlement; the audit event still records the expiry Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mb5McXaNbEDyyCZXPAdGAY
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { NotificationEventType, PlanFeature } 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;
|
||
}
|
||
|
||
// a team that lost the entitlement, for example by downgrading its plan,
|
||
// can no longer re-verify, so nagging its verifiers would be pointless.
|
||
// The audit event alone records the expiry.
|
||
const team = document.team ?? (await document.$get("team"));
|
||
if (!team?.entitlements.includes(PlanFeature.DocumentVerification)) {
|
||
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,
|
||
};
|
||
}
|
||
}
|