Give the intake purge a tombstone, and two health writes their audit row

The dose-history purge was the one destructive verb in the intake family
that removed rows outright. Both siblings, the single-event DELETE and the
bulk delete, stamp `deletedAt` and bump `syncVersion`; the purge called
`deleteMany`, so a mis-tap was final and a client offline at purge time kept
every row forever, because a row that no longer exists produces no tombstone
for the sync feed to carry. It tombstones now, scoped to live rows so a
second purge counts zero. No inventory refund: a purge wipes a history as
bookkeeping, and refunding every dose ever taken would inflate the current
container count instead.

The manual water quick-add and the lab-result un-delete both wrote health
data and reached only the wide event, which expires. Months later nothing
could answer who put a day's total there or who brought a reading back, and
with a second person able to act on a shared record that question has a
second possible answer. Both write a durable row now, named after the
neighbours they sit beside.

The refused-delegation audit comment claimed the row was written for the
owner's benefit. It is not: it is filed under the caller, it is only written
for a header refusal, and a header names an account the caller merely
asserts. Filing under that claim would let anyone write rows into any
account's activity feed by naming it. The comment says what the row is now,
and points at `recordDelegatedAccess`, which is the half the owner does see.

Two comments in the biomarker surfaces still claimed the `SetNull` foreign
key left the readings behind when a marker is deleted. That stopped being
true when delete became a "drop this and its history" action and the
confirmation copy was rewritten in six locales to say so.

The purge route gains a call-shape assertion rather than a count assertion,
because a count comes back identical from a `deleteMany`. The lab restore
route had no test at all and now has one.
This commit is contained in:
Marc-André Bombeck committed 2026-08-03 20:49:27 +02:00
1 parent 837ebcfeea
commit 029c526252
9 files changed
+293 -14

No files matched your search

+17 -4
View File
@@ -648,10 +648,23 @@ async function readActingCarrier(auth: AuthContext): Promise<ActingCarrier> {
/**
* Record a refused delegation.
*
* Written for the OWNER's benefit as much as the operator's: "someone tried to
* open my record and was turned away" is the question the sharing panel exists
* to answer. The row names the actor (the caller), the account they aimed at,
* and why it failed — none of which reaches the response.
* The row is filed under the CALLER, with no actor, and it is the operator's
* trail rather than the owner's. It names who called, the account they claimed,
* and why the claim was refused — none of which reaches the response.
*
* It is deliberately not filed under the claimed account, and that decision is
* worth stating because the opposite reads as the obvious one. A row is only
* written for a HEADER refusal, and a header is an unverified per-request
* assertion: the value is whatever the caller typed. Filing under it would let
* any authenticated caller write rows into any account's activity feed by
* naming it, which is a spam vector aimed at exactly the panel that exists to
* be trustworthy. Verifying the claim first would mean a grant lookup on a path
* whose whole job is to refuse without touching the record.
*
* What the owner does see is the other half: `recordDelegatedAccess` files a
* per-day row under the OWNER, naming the actor, for every delegated read that
* succeeded. "Who reached my record" is answered there. "Whose client sent a
* malformed claim" is an operator question and stays here.
*
* Fire-and-forget: an audit write that fails must not convert a 403 into a 500,
* because the 403 is the part that protects the record.