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

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-05-08 15:00:43 +01:00
parent f181e0fa55
commit 1881054c92
4 changed files with 18 additions and 16 deletions

View File

@@ -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) {

View File

@@ -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'))

View File

@@ -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();

View File

@@ -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;