From 49e9b34cd49eb5fcf0beb7a6e9c91073c1e642f4 Mon Sep 17 00:00:00 2001 From: Matias Perrone Date: Tue, 30 Dec 2025 21:07:47 +0000 Subject: [PATCH 1/3] chore: Add route formatter --- config/audit_log.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/audit_log.php b/config/audit_log.php index 95bbacf8..1213289f 100644 --- a/config/audit_log.php +++ b/config/audit_log.php @@ -1,10 +1,13 @@ [ - \Models\UserAction::class => [ + UserAction::class => [ 'enabled' => true, - 'strategy' => App\Audit\ConcreteFormatters\UserActionAuditLogFormatter::class + 'strategy' => UserActionAuditLogFormatter::class, ], ] ]; \ No newline at end of file From 4c3c9825323e43792fcafaeea12573ba02c29488 Mon Sep 17 00:00:00 2001 From: Matias Perrone Date: Fri, 16 Jan 2026 20:13:25 +0000 Subject: [PATCH 2/3] Fix formatter functionality --- .../UserActionAuditLogFormatter.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php b/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php index 0dbaccf7..705ff8d2 100644 --- a/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php +++ b/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php @@ -18,16 +18,22 @@ public function format($subject, array $change_set): ?string try { $id = $subject->getId() ?? 'unknown'; $title = $subject->getUserAction() ?? 'Unknown UserAction'; + $owner = $subject->getOwner(); + $realm = $subject->hasRealm() ? $subject->getRealm() : 'N/A'; + $ip = $subject->getFromIp(); switch ($this->event_type) { + case IAuditStrategy::EVENT_ENTITY_CREATION: - return sprintf("UserAction (%s) for '%s' created by user %s", $id, $title, $this->getUserInfo()); + return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was created by user %s", $id, $title, $owner->getFullName(), $owner->getID(), $realm, $ip, $this->getUserInfo()); case IAuditStrategy::EVENT_ENTITY_UPDATE: $details = $this->buildChangeDetails($change_set); - return sprintf("UserAction (%s) for '%s' updated: %s by user %s", $id, $title, $details, $this->getUserInfo()); + 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, $owner->getFullName(), $owner->getID(), $realm, $ip, $details, $this->getUserInfo()); case IAuditStrategy::EVENT_ENTITY_DELETION: - return sprintf("UserAction (%s) for '%s' deleted by user %s", $id, $title, $this->getUserInfo()); + return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was deleted by user %s", $id, $title, $owner->getFullName(), $owner->getID(), $realm, $ip, $this->getUserInfo()); } + return ""; + } catch (\Exception $ex) { Log::warning("UserAction error: " . $ex->getMessage()); } From cc94ac8563d405b387dfd6f22142bb21403f328f Mon Sep 17 00:00:00 2001 From: Matias Perrone Date: Tue, 20 Jan 2026 19:14:05 +0000 Subject: [PATCH 3/3] chore: update non existent info messages --- .../UserActionAuditLogFormatter.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php b/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php index 705ff8d2..3738319f 100644 --- a/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php +++ b/app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php @@ -19,20 +19,22 @@ public function format($subject, array $change_set): ?string $id = $subject->getId() ?? 'unknown'; $title = $subject->getUserAction() ?? 'Unknown UserAction'; $owner = $subject->getOwner(); + $ownerFullName = $owner ? $owner->getFullName() : 'Unknown'; + $ownerID = $owner ? $owner->getID() : 'N/A'; $realm = $subject->hasRealm() ? $subject->getRealm() : 'N/A'; - $ip = $subject->getFromIp(); + $ip = $subject->getFromIp() ?? 'Unknown'; switch ($this->event_type) { case IAuditStrategy::EVENT_ENTITY_CREATION: - return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was created by user %s", $id, $title, $owner->getFullName(), $owner->getID(), $realm, $ip, $this->getUserInfo()); + 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()); case IAuditStrategy::EVENT_ENTITY_UPDATE: $details = $this->buildChangeDetails($change_set); - 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, $owner->getFullName(), $owner->getID(), $realm, $ip, $details, $this->getUserInfo()); + 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()); case IAuditStrategy::EVENT_ENTITY_DELETION: - return sprintf("UserAction (%s) for '%s' which owner is \"%s (%s)\", with realm \"%s\" and IP \"%s\" was deleted by user %s", $id, $title, $owner->getFullName(), $owner->getID(), $realm, $ip, $this->getUserInfo()); + 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()); } - return ""; + return null; } catch (\Exception $ex) { Log::warning("UserAction error: " . $ex->getMessage());