Skip to content

A free open source IT asset/license management system

Fixed #16863 - better handle unique not required custom field redirects

snipe1881054c92b8
diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php
index bc9ae19c8e..083975867b 100644
--- a/app/Http/Controllers/Assets/AssetCheckinController.php
+++ b/app/Http/Controllers/Assets/AssetCheckinController.php
@@ -42,12 +42,11 @@ class AssetCheckinController extends Controller
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());
+ // Invoke the validation to see if the audit will complete successfully
+ $asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
- if ($validator->fails()) {
- return redirect()->route('hardware.edit', $asset)
- ->withErrors($validator);
+ if ($asset->isInvalid()) {
+ return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
}
$target_option = match ($asset->assigned_type) {
diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php
index 26a993d808..da2c0a2550 100644
--- a/app/Http/Controllers/Assets/AssetCheckoutController.php
+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php
@@ -37,13 +37,13 @@ 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());
+ // Invoke the validation to see if the audit will complete successfully
+ $asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
- if ($validator->fails()) {
- return redirect()->route('hardware.edit', $asset)
- ->withErrors($validator);
+ if ($asset->isInvalid()) {
+ return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
}
+
if ($asset->availableForCheckout()) {
return view('hardware/checkout', compact('asset'))
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php
index c47741b5a3..12cb93ff3e 100755
--- a/app/Http/Controllers/Assets/AssetsController.php
+++ b/app/Http/Controllers/Assets/AssetsController.php
@@ -882,12 +882,12 @@ class AssetsController extends Controller
$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);
+ // Invoke the validation to see if the audit will complete successfully
+ $asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
+
+ if ($asset->isInvalid()) {
+ return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
}
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php
index bf04817685..e5490b49b3 100644
--- a/app/Models/CustomFieldset.php
+++ b/app/Models/CustomFieldset.php
@@ -113,7 +113,10 @@ class CustomFieldset extends Model
$rule[] = 'unique_undeleted';
}
- array_push($rule, $field->attributes['format']);
+ if ($field->attributes['format']!='') {
+ array_push($rule, $field->attributes['format']);
+ }
+
$rules[$field->db_column_name()] = $rule;