Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed asset show page erroring when asset not associated with model #16106

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,21 +1384,23 @@ class="table table-striped snipe-table"
</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">

<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
@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" />

</div> <!-- /.col-md-12 -->
</div> <!-- /.row -->
</div> <!-- /.tab-pane files -->
@endcan
@endif
</div><!-- /.tab-content -->
</div><!-- nav-tabs-custom -->
</div>
Expand All @@ -1420,4 +1422,4 @@ class="table table-striped snipe-table"
</script>
@include ('partials.bootstrap-table')

@stop
@stop
26 changes: 26 additions & 0 deletions tests/Feature/Assets/Ui/ShowAssetTest.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading