Keep a deleted-but-held account's audit and journal records under the hold #381

Merged
jcoffey-dev merged 1 commits from fix/legal-hold-audit-purge into main 2026-11-11 19:43:28 +00:00
3 changed files with 25 additions and 10 deletions

No files matched your search

+10
View File
@@ -301,6 +301,16 @@ impl Server {
held.insert(account_id);
}
}
// LH-6, AU-7: accounts deleted while undelete keeps them can still be
// held, through the domain and tenant their kept record carries. They
// have dropped out of the live-account scan above, so fold them in --
// otherwise a purge that keeps a held account's records (audit, journal)
// would drop a deleted-but-held account's, the exact case a hold is for.
for (account_id, kept) in undelete_data::kept_accounts(self.store()).await? {
if self.is_kept_held(account_id, &kept).await? {
held.insert(account_id);
}
}
Ok(held)
}
@@ -433,16 +433,8 @@ async fn store_maintenance(
/// (deleted accounts a hold keeps included), and records how many went.
async fn purge_journal(server: &Server) -> trc::Result<()> {
use inbuxa_features::audit::{Action, Actor, Outcome, Record, Target};
let mut held = server.held_accounts().await?;
if !held.is_empty() {
for (account_id, kept) in
inbuxa_features::undelete::data::kept_accounts(server.store()).await?
{
if server.is_kept_held(account_id, &kept).await? {
held.insert(account_id);
}
}
}
// held_accounts() already folds in deleted-but-kept accounts a hold covers.
let held = server.held_accounts().await?;
let at = store::write::now();
let purged = inbuxa_features::journal::entries::purge(server.store(), at, |entry| {
entry.accounts.iter().any(|account| held.contains(account))
+13
View File
@@ -962,6 +962,19 @@ pub async fn test(test: &mut TestServer) {
summary["sizeHeld"].as_u64().is_some_and(|s| s > 0),
"LH-8: the held size is zero for a deleted-then-held account: {response}"
);
// LH-6, AU-7: a hold must also keep the records ABOUT a deleted-but-held
// account. held_accounts() -- the set the audit and journal purges keep --
// has to include the gone custodian, or its audit trail is purged out from
// under the hold. On the buggy path the live-account scan never sees it.
assert!(
test.server
.held_accounts()
.await
.unwrap()
.contains(&departed_id.document_id()),
"LH-6/AU-7: the deleted-but-held custodian is missing from held_accounts()"
);
}
async fn import(