Merge pull request #16106 from marcusmoore/bug/sc-27960

Fixed asset show page erroring when asset not associated with model
This commit is contained in:
snipe 2025-02-24 17:16:12 +00:00 committed by GitHub
commit 5fa4f85c20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 13 deletions

View file

@ -1440,21 +1440,23 @@
</div> <!-- /.row -->
</div> <!-- /.tab-pane files -->
@can('view', $asset->model)
<div class="tab-pane fade" id="modelfiles">
<div class="row{{ (($asset->model) && ($asset->model->uploads->count() > 0)) ? '' : ' hidden-print' }}">
<div class="col-md-12">
@if ($asset->model)
@can('view', $asset->model)
<div class="tab-pane fade" id="modelfiles">
<div class="row{{ (($asset->model) && ($asset->model->uploads->count() > 0)) ? '' : ' hidden-print' }}">
<div class="col-md-12">
<x-filestable
filepath="private_uploads/assetmodels/"
showfile_routename="show/modelfile"
deletefile_routename="delete/modelfile"
:object="$asset->model" />
<x-filestable
filepath="private_uploads/assetmodels/"
showfile_routename="show/modelfile"
deletefile_routename="delete/modelfile"
:object="$asset->model" />
</div> <!-- /.col-md-12 -->
</div> <!-- /.row -->
</div> <!-- /.tab-pane files -->
@endcan
</div> <!-- /.col-md-12 -->
</div> <!-- /.row -->
</div> <!-- /.tab-pane files -->
@endcan
@endif
</div><!-- /.tab-content -->
</div><!-- nav-tabs-custom -->
</div>

View file

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\Assets\Ui;
use App\Models\Asset;
use App\Models\User;
use Tests\TestCase;
class ShowAssetTest extends TestCase
{
public function testPageForAssetWithMissingModelStillRenders()
{
$asset = Asset::factory()->create();
$asset->model_id = null;
$asset->forceSave();
$asset->refresh();
$this->assertNull($asset->fresh()->model_id, 'This test needs model_id to be null to be helpful.');
$this->actingAs(User::factory()->superuser()->create())
->get(route('hardware.show', $asset))
->assertOk();
}
}