Skip to content

Commit 545d148

Browse files
committed
fix(audit): populate user_name in createAuditTrailEntry
The migration (Version1Date20260423100000) relaxed NOT NULL on `user_name` so referential-integrity rows can land without a displayable actor. The risk: the relax applies unconditionally, so any future code path that forgets to set `user_name` for a normal create/update silently inserts a row with no human-readable trace of the actor. `createAuditTrailEntry()` (used by ImportService and downstream consumers) was such a path — it set `user`, but never `user_name`. Backfill from `$user->getDisplayName()` when a session user is present, fall back to `'System'` (matches the convention in `createAuditTrail()`). A migration-level CHECK constraint (`(user_name IS NOT NULL) OR (action LIKE 'referential_integrity.%')`) is the more durable answer; this fix is the in-mapper backstop. Refs: #1419 review (concern 9) — discussion_r3187494503
1 parent 07e0837 commit 545d148

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/Db/AuditTrailMapper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,16 @@ public function createAuditTrailEntry(
15051505
$auditTrail->setAction($action);
15061506
$auditTrail->setChanged($context);
15071507
$auditTrail->setUser($userId);
1508+
1509+
// SECURITY / AVG: keep `user_name` populated even though the
1510+
// migration (Version1Date20260423100000) relaxed NOT NULL on
1511+
// the column to support referential-integrity rows that have
1512+
// no displayable actor. Without this default, every audit row
1513+
// produced through this entry point would persist with a NULL
1514+
// `user_name` — undermining GDPR Art 30 §4 supervisor review.
1515+
$userName = $user !== null ? $user->getDisplayName() : 'System';
1516+
$auditTrail->setUserName($userName);
1517+
15081518
$auditTrail->setCreated(new DateTime());
15091519

15101520
return $this->insert(entity: $auditTrail);

0 commit comments

Comments
 (0)