mirror of
https://github.com/outline/outline.git
synced 2026-12-01 17:32:49 +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
109 lines
3.4 KiB
TypeScript
109 lines
3.4 KiB
TypeScript
import { subDays, subHours } from "date-fns";
|
|
import { NotificationEventType } from "@shared/types";
|
|
import { Notification } from "@server/models";
|
|
import type { DocumentEvent } from "@server/types";
|
|
import { buildDocument, buildTeam, buildUser } from "@server/test/factories";
|
|
import DocumentVerificationExpiredNotificationsTask from "./DocumentVerificationExpiredNotificationsTask";
|
|
|
|
vi.setConfig({ testTimeout: 30000 });
|
|
|
|
describe("DocumentVerificationExpiredNotificationsTask", () => {
|
|
let task: DocumentVerificationExpiredNotificationsTask;
|
|
|
|
beforeEach(() => {
|
|
task = new DocumentVerificationExpiredNotificationsTask();
|
|
});
|
|
|
|
const buildExpiredDocument = async () => {
|
|
const team = await buildTeam();
|
|
const verifier = await buildUser({ teamId: team.id });
|
|
const document = await buildDocument({
|
|
teamId: team.id,
|
|
userId: verifier.id,
|
|
verifiedAt: subDays(new Date(), 30),
|
|
verifiedById: verifier.id,
|
|
verificationExpiresAt: subHours(new Date(), 12),
|
|
});
|
|
const event = {
|
|
name: "documents.verification_expired",
|
|
documentId: document.id,
|
|
collectionId: document.collectionId,
|
|
teamId: team.id,
|
|
data: {
|
|
expiresAt: document.verificationExpiresAt!.toISOString(),
|
|
},
|
|
} as DocumentEvent;
|
|
|
|
return { team, verifier, document, event };
|
|
};
|
|
|
|
const countNotifications = (userId: string) =>
|
|
Notification.count({
|
|
where: {
|
|
event: NotificationEventType.VerificationExpired,
|
|
userId,
|
|
},
|
|
});
|
|
|
|
it("creates a notification for an active verifier", async () => {
|
|
const { verifier, document, event } = await buildExpiredDocument();
|
|
|
|
await task.perform(event);
|
|
|
|
expect(await countNotifications(verifier.id)).toBe(1);
|
|
const notification = await Notification.findOne({
|
|
where: {
|
|
event: NotificationEventType.VerificationExpired,
|
|
userId: verifier.id,
|
|
},
|
|
});
|
|
expect(notification?.documentId).toEqual(document.id);
|
|
});
|
|
|
|
it("creates no notification when the verifier is suspended", async () => {
|
|
const { verifier, event } = await buildExpiredDocument();
|
|
await verifier.update({ suspendedAt: new Date() });
|
|
|
|
await task.perform(event);
|
|
|
|
expect(await countNotifications(verifier.id)).toBe(0);
|
|
});
|
|
|
|
it("creates no notification when the verifier was deleted", async () => {
|
|
const { team, verifier, document, event } = await buildExpiredDocument();
|
|
await buildUser({ teamId: team.id });
|
|
// deleting a user nulls the verifier reference via the FK
|
|
await document.update({ verifiedById: null });
|
|
await verifier.destroy();
|
|
|
|
await task.perform(event);
|
|
|
|
expect(await countNotifications(verifier.id)).toBe(0);
|
|
});
|
|
|
|
it("creates no notification when the document was re-verified since", async () => {
|
|
const { verifier, document, event } = await buildExpiredDocument();
|
|
await document.update({
|
|
verifiedAt: new Date(),
|
|
verificationExpiresAt: subDays(new Date(), -30),
|
|
});
|
|
|
|
await task.perform(event);
|
|
|
|
expect(await countNotifications(verifier.id)).toBe(0);
|
|
});
|
|
|
|
it("creates no notification when the verifier unsubscribed from the event", async () => {
|
|
const { verifier, event } = await buildExpiredDocument();
|
|
await verifier.update({
|
|
notificationSettings: {
|
|
[NotificationEventType.VerificationExpired]: false,
|
|
},
|
|
});
|
|
|
|
await task.perform(event);
|
|
|
|
expect(await countNotifications(verifier.id)).toBe(0);
|
|
});
|
|
});
|