A free open source IT asset/license management system
Invoke a validator, redirect to edit screen if invalid
snipe5086c806582f
diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.phpindex cf881b57c7..bc9ae19c8e 100644--- a/app/Http/Controllers/Assets/AssetCheckinController.php+++ b/app/Http/Controllers/Assets/AssetCheckinController.php@@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Builder;use Illuminate\Support\Facades\Log;use \Illuminate\Contracts\View\View;use \Illuminate\Http\RedirectResponse;+use Illuminate\Support\Facades\Validator;class AssetCheckinController extends Controller{@@ -40,6 +41,15 @@ class AssetCheckinController extends Controllerif (!$asset->model) {return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));}++ // Validate custom fields on existing asset+ $validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());++ if ($validator->fails()) {+ return redirect()->route('hardware.edit', $asset)+ ->withErrors($validator);+ }+$target_option = match ($asset->assigned_type) {'App\Models\Asset' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset_previous')]),'App\Models\Location' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.location')]),diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.phpindex 4d8c9ffda2..26a993d808 100644--- a/app/Http/Controllers/Assets/AssetCheckoutController.php+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php@@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;use Illuminate\Support\Facades\Session;use \Illuminate\Contracts\View\View;use \Illuminate\Http\RedirectResponse;+use Illuminate\Support\Facades\Validator;class AssetCheckoutController extends Controller{@@ -36,6 +37,14 @@ class AssetCheckoutController extends Controller->with('error', trans('admin/hardware/general.model_invalid_fix'));}+ // Validate custom fields on existing asset+ $validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());++ if ($validator->fails()) {+ return redirect()->route('hardware.edit', $asset)+ ->withErrors($validator);+ }+if ($asset->availableForCheckout()) {return view('hardware/checkout', compact('asset'))->with('statusLabel_list', Helper::deployableStatusLabelList())diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.phpindex 6391a3dd9f..50810b0434 100755--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@ -877,10 +877,19 @@ class AssetsController extends Controller}- public function audit(Asset $asset)+ public function audit(Asset $asset): View | RedirectResponse{- $settings = Setting::getSettings();$this->authorize('audit', Asset::class);+ $settings = Setting::getSettings();++ // Validate custom fields on existing asset+ $validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());++ if ($validator->fails()) {+ return redirect()->route('hardware.edit', $asset)+ ->withErrors($validator);+ }+$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();return view('hardware/audit')->with('asset', $asset)->with('item', $asset)->with('next_audit_date', $dt)->with('locations_list');}