Added slightly friendlier error handling for assets without models

This scenario should never happen, barring someone manually editing their data, but better to handle that scenario in a more user-friendly way.
This commit is contained in:
snipe 2019-12-06 18:17:03 -08:00
parent 943cf40247
commit 88fb1370f0
4 changed files with 42 additions and 20 deletions

View file

@ -604,20 +604,26 @@ class Asset extends Depreciable
public function requireAcceptance() public function requireAcceptance()
{ {
return $this->model->category->require_acceptance; if (($this->model) && ($this->model->category)) {
return $this->model->category->require_acceptance;
}
} }
public function getEula() public function getEula()
{ {
$Parsedown = new \Parsedown(); $Parsedown = new \Parsedown();
if ($this->model->category->eula_text) { if (($this->model) && ($this->model->category)) {
return $Parsedown->text(e($this->model->category->eula_text)); if ($this->model->category->eula_text) {
} elseif ($this->model->category->use_default_eula == '1') { return $Parsedown->text(e($this->model->category->eula_text));
return $Parsedown->text(e(Setting::getSettings()->default_eula_text)); } elseif ($this->model->category->use_default_eula == '1') {
} else { return $Parsedown->text(e(Setting::getSettings()->default_eula_text));
return false; } else {
return false;
}
} }
return false;
} }
/** /**

View file

@ -395,7 +395,7 @@ class AssetPresenter extends Presenter
public function eol_date() public function eol_date()
{ {
if (( $this->purchase_date ) && ( $this->model ) && ($this->model->model->eol) ) { if (( $this->purchase_date ) && ( $this->model->model ) && ($this->model->model->eol) ) {
$date = date_create($this->purchase_date); $date = date_create($this->purchase_date);
date_add($date, date_interval_create_from_date_string($this->model->model->eol . ' months')); date_add($date, date_interval_create_from_date_string($this->model->model->eol . ' months'));
return date_format($date, 'Y-m-d'); return date_format($date, 'Y-m-d');

View file

@ -35,15 +35,24 @@
action="{{ route('checkin/hardware', $asset->id) }}" autocomplete="off"> action="{{ route('checkin/hardware', $asset->id) }}" autocomplete="off">
@endif @endif
{{csrf_field()}} {{csrf_field()}}
@if ($asset->model->name)
<!-- AssetModel name --> <!-- AssetModel name -->
<div class="form-group"> <div class="form-group">
{{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }} {{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8"> <div class="col-md-8">
<p class="form-control-static">{{ $asset->model->name }}</p> <p class="form-control-static">
@if (($asset->model) && ($asset->model->name))
{{ $asset->model->name }}
@else
<span class="text-danger text-bold">
<i class="fa fa-exclamation-triangle"></i>This asset's model is invalid!
The asset <a href="{{ route('hardware.edit', $asset->id) }}">should be edited</a> to correct this before attempting to check it in or out.</span>
@endif
</p>
</div> </div>
</div> </div>
@endif
<!-- Asset Name --> <!-- Asset Name -->
<div class="form-group {{ $errors->has('name') ? 'error' : '' }}"> <div class="form-group {{ $errors->has('name') ? 'error' : '' }}">

View file

@ -26,15 +26,22 @@
</div> </div>
<div class="box-body"> <div class="box-body">
{{csrf_field()}} {{csrf_field()}}
@if ($asset->model->name) <!-- AssetModel name -->
<!-- Model name --> <div class="form-group">
<div class="form-group {{ $errors->has('name') ? 'error' : '' }}">
{{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }} {{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8"> <div class="col-md-8">
<p class="form-control-static">{{ $asset->model->name }}</p> <p class="form-control-static">
</div> @if (($asset->model) && ($asset->model->name))
{{ $asset->model->name }}
@else
<span class="text-danger text-bold">
<i class="fa fa-exclamation-triangle"></i>This asset's model is invalid!
The asset <a href="{{ route('hardware.edit', $asset->id) }}">should be edited</a> to correct this before attempting to check it in or out.</span>
@endif
</p>
</div>
</div> </div>
@endif
<!-- Asset Name --> <!-- Asset Name -->
<div class="form-group {{ $errors->has('name') ? 'error' : '' }}"> <div class="form-group {{ $errors->has('name') ? 'error' : '' }}">