Skip to content

Commit e512e92

Browse files
Feature | Add UserAction formatter (#97)
* chore: Add route formatter * Fix formatter functionality * chore: update non existent info messages --------- Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent e13973c commit e512e92

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ public function format($subject, array $change_set): ?string
1818
try {
1919
$id = $subject->getId() ?? 'unknown';
2020
$title = $subject->getUserAction() ?? 'Unknown UserAction';
21+
$owner = $subject->getOwner();
22+
$ownerFullName = $owner ? $owner->getFullName() : 'Unknown';
23+
$ownerID = $owner ? $owner->getID() : 'N/A';
24+
$realm = $subject->hasRealm() ? $subject->getRealm() : 'N/A';
25+
$ip = $subject->getFromIp() ?? 'Unknown';
2126

2227
switch ($this->event_type) {
28+
2329
case IAuditStrategy::EVENT_ENTITY_CREATION:
24-
return sprintf("UserAction (%s) for '%s' created by user %s", $id, $title, $this->getUserInfo());
30+
return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was created by user %s", $id, $title, $ownerFullName, $ownerID, $realm, $ip, $this->getUserInfo());
2531
case IAuditStrategy::EVENT_ENTITY_UPDATE:
2632
$details = $this->buildChangeDetails($change_set);
27-
return sprintf("UserAction (%s) for '%s' updated: %s by user %s", $id, $title, $details, $this->getUserInfo());
33+
return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was updated: %s by user %s", $id, $title, $ownerFullName, $ownerID, $realm, $ip, $details, $this->getUserInfo());
2834
case IAuditStrategy::EVENT_ENTITY_DELETION:
29-
return sprintf("UserAction (%s) for '%s' deleted by user %s", $id, $title, $this->getUserInfo());
35+
return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was deleted by user %s", $id, $title, $ownerFullName, $ownerID, $realm, $ip, $this->getUserInfo());
3036
}
37+
return null;
38+
3139
} catch (\Exception $ex) {
3240
Log::warning("UserAction error: " . $ex->getMessage());
3341
}

config/audit_log.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3+
use App\Audit\ConcreteFormatters\UserActionAuditLogFormatter;
4+
use Models\UserAction;
5+
36
return [
47
'entities' => [
5-
\Models\UserAction::class => [
8+
UserAction::class => [
69
'enabled' => true,
7-
'strategy' => App\Audit\ConcreteFormatters\UserActionAuditLogFormatter::class
10+
'strategy' => UserActionAuditLogFormatter::class,
811
],
912
]
1013
];

0 commit comments

Comments
 (0)