From 63e733f0d6b553d2776f0ff6ca6cdd256f646a0c Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 30 Jan 2024 15:14:59 -0600 Subject: [PATCH] changes from a note to a source --- app/Models/Actionlog.php | 16 +++++++++++++++- app/Observers/AccessoryObserver.php | 2 +- app/Observers/AssetObserver.php | 2 +- app/Observers/ComponentObserver.php | 2 +- app/Observers/ConsumableObserver.php | 2 +- app/Observers/LicenseObserver.php | 2 +- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index bc08aa800a..90e0e884f8 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -19,6 +19,9 @@ class Actionlog extends SnipeModel { use HasFactory; + // This is to manually set the source (via setActionSource()) for determineActionSource() + protected ?string $source = null; + protected $presenter = \App\Presenters\ActionlogPresenter::class; use SoftDeletes; use Presentable; @@ -341,7 +344,12 @@ class Actionlog extends SnipeModel * @since v6.3.0 * @return string */ - public function determineActionSource() { + public function determineActionSource(): string + { + // This is a manually set source + if($this->source) { + return $this->source; + } // This is an API call if (((request()->header('content-type') && (request()->header('accept'))=='application/json')) @@ -358,4 +366,10 @@ class Actionlog extends SnipeModel return 'cli/unknown'; } + + // Manually sets $this->source for determineActionSource() + public function setActionSource($source = null): void + { + $this->source = $source; + } } diff --git a/app/Observers/AccessoryObserver.php b/app/Observers/AccessoryObserver.php index 99a594c5bc..ddf29681be 100644 --- a/app/Observers/AccessoryObserver.php +++ b/app/Observers/AccessoryObserver.php @@ -39,7 +39,7 @@ class AccessoryObserver $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); if($accessory->imported) { - $logAction->note = trans('general.importer.import_note'); + $logAction->setActionSource('importer'); } $logAction->logaction('create'); } diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index c94a7046e0..8fcf2485a3 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -110,7 +110,7 @@ class AssetObserver $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); if($asset->imported) { - $logAction->note = trans('general.importer.import_note'); + $logAction->setActionSource('importer'); } $logAction->logaction('create'); } diff --git a/app/Observers/ComponentObserver.php b/app/Observers/ComponentObserver.php index e89006ad85..a8bb386e8e 100644 --- a/app/Observers/ComponentObserver.php +++ b/app/Observers/ComponentObserver.php @@ -39,7 +39,7 @@ class ComponentObserver $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); if($component->imported) { - $logAction->note = trans('general.importer.import_note'); + $logAction->setActionSource('importer'); } $logAction->logaction('create'); } diff --git a/app/Observers/ConsumableObserver.php b/app/Observers/ConsumableObserver.php index 265e64d73e..1f0c777dcc 100644 --- a/app/Observers/ConsumableObserver.php +++ b/app/Observers/ConsumableObserver.php @@ -39,7 +39,7 @@ class ConsumableObserver $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); if($consumable->imported) { - $logAction->note = trans('general.importer.import_note'); + $logAction->setActionSource('importer'); } $logAction->logaction('create'); } diff --git a/app/Observers/LicenseObserver.php b/app/Observers/LicenseObserver.php index 2d0f60a625..0628020965 100644 --- a/app/Observers/LicenseObserver.php +++ b/app/Observers/LicenseObserver.php @@ -39,7 +39,7 @@ class LicenseObserver $logAction->created_at = date('Y-m-d H:i:s'); $logAction->user_id = Auth::id(); if($license->imported) { - $logAction->note = trans('general.importer.import_note'); + $logAction->setActionSource('importer'); } $logAction->logaction('create'); }