Handle asset maintenances that do not have a valid asset associated

This commit is contained in:
snipe 2019-01-16 02:26:42 -08:00
parent 74c099f0b3
commit 1eace04ad9
3 changed files with 14 additions and 2 deletions

View file

@ -162,6 +162,10 @@ class AssetMaintenancesController extends Controller
// Redirect to the improvement management page // Redirect to the improvement management page
return redirect()->route('maintenances.index') return redirect()->route('maintenances.index')
->with('error', trans('admin/asset_maintenances/message.not_found')); ->with('error', trans('admin/asset_maintenances/message.not_found'));
} elseif (!$assetMaintenance->asset) {
return redirect()->route('maintenances.index')
->with('error', 'The asset associated with this maintenance does not exist.');
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) { } elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect(); return static::getInsufficientPermissionsRedirect();
} }

View file

@ -28,10 +28,15 @@ class AssetMaintenancesTransformer
'asset_tag'=> e($assetmaintenance->asset->asset_tag) 'asset_tag'=> e($assetmaintenance->asset->asset_tag)
] : null, ] : null,
'model' => ($assetmaintenance->asset->model) ? [ 'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [
'id' => (int) $assetmaintenance->asset->model->id, 'id' => (int) $assetmaintenance->asset->model->id,
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null 'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null
] : null, ] : null,
'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [
'id' => (int) $assetmaintenance->asset->company->id,
'name'=> ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null,
] : null,
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null, 'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [ 'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
'id' => (int) $assetmaintenance->asset->location->id, 'id' => (int) $assetmaintenance->asset->location->id,

View file

@ -423,8 +423,11 @@
} }
function assetTagLinkFormatter(value, row) { function assetTagLinkFormatter(value, row) {
if ((row.asset) && (row.asset.id)) {
return '<a href="{{ url('/') }}/hardware/' + row.asset.id + '"> ' + row.asset.asset_tag + '</a>'; return '<a href="{{ url('/') }}/hardware/' + row.asset.id + '"> ' + row.asset.asset_tag + '</a>';
} }
return '';
}
function assetNameLinkFormatter(value, row) { function assetNameLinkFormatter(value, row) {
if ((row.asset) && (row.asset.name)) { if ((row.asset) && (row.asset.name)) {