Skip to content

A free open source IT asset/license management system

Account for deleted adminuser in journal note for assets

snipe3cff19f9caad
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php
index 9152ed20db..479a0f234a 100755
--- a/resources/views/hardware/view.blade.php
+++ b/resources/views/hardware/view.blade.php
@@ -206,7 +206,7 @@
{{ $asset->journal->last()->note }}
<i class="fa-solid fa-quote-right"></i>
<span class="text-muted">
- - {!! $asset->journal->last()->adminuser->present()->formattedNameLink !!}
+ - {!! $asset->journal->last()->adminuser?->present()->formattedNameLink !!}
({{ Helper::getFormattedDateObject($asset->journal->last()->created_at, 'datetime', false) }})
</span>
</x-data-row>
diff --git a/tests/Feature/Assets/Ui/ShowAssetTest.php b/tests/Feature/Assets/Ui/ShowAssetTest.php
index ce2a855188..c01d46e381 100644
--- a/tests/Feature/Assets/Ui/ShowAssetTest.php
+++ b/tests/Feature/Assets/Ui/ShowAssetTest.php
@@ -2,6 +2,7 @@
namespace Tests\Feature\Assets\Ui;
+use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\User;
use Tests\TestCase;
@@ -25,6 +26,22 @@ class ShowAssetTest extends TestCase
->assertOk();
}
+ public function test_page_renders_when_journal_note_has_no_author()
+ {
+ $asset = Asset::factory()->create();
+
+ Actionlog::factory()->for($asset, 'item')->create([
+ 'action_type' => 'note added',
+ 'item_type' => Asset::class,
+ 'note' => 'A note with no author',
+ 'created_by' => null,
+ ]);
+
+ $this->actingAs(User::factory()->viewAssets()->create())
+ ->get(route('hardware.show', $asset))
+ ->assertOk();
+ }
+
public function test_page_for_asset_with_missing_model_still_renders()
{
$asset = Asset::factory()->create();