changes from a note to a source

This commit is contained in:
spencerrlongg 2024-01-30 15:14:59 -06:00
parent 2deba17d91
commit 63e733f0d6
6 changed files with 20 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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');
}

View file

@ -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');
}

View file

@ -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');
}

View file

@ -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');
}

View file

@ -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');
}