Skip to content

Commit

Permalink
Ensure we do not miss any updates if only sensitive fields have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosp committed Aug 29, 2024
1 parent 1bb48c0 commit 1ceebd5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Model/Behavior/AuditLogBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ public function afterSave(
return;
}

$this->redactArray($changed);

$original = $entity->extractOriginal(array_keys($changed));
$this->redactArray($original);

$properties = $this->getAssociationProperties(array_keys($options['associated']));
foreach ($properties as $property) {
Expand All @@ -157,6 +154,9 @@ public function afterSave(
return;
}

$this->redactArray($changed);
$this->redactArray($original);

$primary = $entity->extract((array)$this->_table->getPrimaryKey());
$auditEvent = $entity->isNew() ? AuditCreateEvent::class : AuditUpdateEvent::class;

Expand Down
1 change: 0 additions & 1 deletion tests/TestCase/Model/Behavior/AuditLogBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ public function testSensitiveFields(): void
'author_id' => 1,
];
$entity = new Entity($data, ['markNew' => false, 'markClean' => true]);
$entity->author_id = 50;
$entity->body = 'The changed body';

$event = new Event('Model.afterSave');
Expand Down

0 comments on commit 1ceebd5

Please sign in to comment.