Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Keep the retention period from cutting a scheduled deletion short
Claudec313f578ed83
diff --git a/src/lib/retention.ts b/src/lib/retention.tsindex 97baffd..549e992 100644--- a/src/lib/retention.ts+++ b/src/lib/retention.ts@@ -769,6 +769,13 @@ async function listFinishedEnvelopesToHandle(-- Part 11 records are kept for as long as the rules that apply to-- them say, never by this timer.AND NOT e.part11+ -- An administrator's scheduled deletion has its own notice and+ -- wait, which this timer must not cut short.+ AND NOT EXISTS (+ SELECT 1+ FROM scheduled_envelope_deletions s+ WHERE s.envelope_id = e.id AND s.cancelled_at IS NULL+ )AND ((e.retention_warned_at IS NULLdiff --git a/src/lib/signature-evidence.dbtest.ts b/src/lib/signature-evidence.dbtest.tsindex 49ffd7e..9f7b12b 100644--- a/src/lib/signature-evidence.dbtest.ts+++ b/src/lib/signature-evidence.dbtest.ts@@ -321,3 +321,64 @@ test("the retention period never warns about or deletes a Part 11 record", asyncassert.equal(await envelopeOwner(record), owner);assert.equal(sent.includes(`${owner}@example.test`), false);});++test("the retention period leaves an envelope alone while its scheduled deletion waits", async () => {+ const owner = await createUser();+ const now = 2_000_000_000;+ const day = 24 * 60 * 60;+ const record = await createEnvelope(+ owner,+ "completed",+ "[email protected]",+ now - 400 * day,+ );+ const emailService = {+ send: async (message: { to: string }) => ({+ accepted: [message.to],+ rejected: [],+ }),+ sendBatch: async () => [],+ } as unknown as EmailService;++ // Warned long ago, and past the period: due under the timer.+ await database.query(+ `update envelopes set retention_warned_at = $1 where id = $2`,+ [now - 60 * day, record],+ );+ await database.query(+ `insert into app_settings (id, signup_mode, retention_days, created_at, updated_at)+ values (true, 'closed', 30, 1, 1)+ on conflict (id) do update set retention_days = 30`,+ );+ // An administrator asked for it to go in two weeks instead.+ await database.query(+ `+ insert into scheduled_envelope_deletions (+ envelope_id, requested_by_user_id, requested_by_email, requested_at,+ delete_after, sender_notified_at+ ) values ($1, $2, '[email protected]', $3, $4, $3)+ `,+ [record, owner, now, now + 14 * day],+ );++ await runRetentionSweep({+ database,+ emailService,+ now,+ storageService: storage(),+ });+ assert.equal(await envelopeOwner(record), owner);++ // Cancelled: the timer applies again.+ await database.query(+ `update scheduled_envelope_deletions set cancelled_at = $1, cancelled_by_user_id = $2 where envelope_id = $3`,+ [now + day, owner, record],+ );+ await runRetentionSweep({+ database,+ emailService,+ now: now + day,+ storageService: storage(),+ });+ assert.equal(await envelopeOwner(record), null);+});