fix(managed-profiles): pending deletion closes handovers and the Guardian count

A handover link stayed claimable after its profile was deleted: the claim
gave the profile credentials that every sign-in then refused, and the purge
erased the account someone had just taken over. Locking an account for
deletion now revokes the open links for that profile and the links that
account minted, and creating, previewing and claiming a link refuse a profile
pending deletion, the claim under the record lock.

The last-Guardian rule counted Guardians pending deletion and profiles
pending deletion. A Guardian who had deleted their only profile could not
delete their own account; two Guardians sharing a profile could both leave,
and the second one's erasure was then refused on every run. The rule now
counts only Guardians whose account is not pending deletion, ignores profiles
pending deletion, and is decided under the record lock for account deletion,
data wipe, revoking and renouncing a Guardian. An admin's undo of a managed
profile with no such Guardian left is refused (409
account.deletion.no_guardian).
This commit is contained in:
Marc-André Bombeck committed 2026-10-25 17:02:32 +01:00
1 parent b37e4f5df7
commit be78517500
7 files changed
+344 -34

No files matched your search

@@ -43,6 +43,13 @@ export const POST = apiHandler(
ipAddress: getClientIp(request),
});
if (outcome === "not_found") return apiError("User not found", 404);
if (outcome === "no_guardian") {
return apiError(
"This managed profile has no Guardian left to give it back to. Its Guardians deleted their accounts or left it during the window.",
409,
{ errorCode: "account.deletion.no_guardian" },
);
}
if (outcome === "not_pending") {
return apiError("This account is not pending deletion", 409, {
errorCode: "account.deletion.not_pending",