Skip to content

Commit 1881054

Browse files
committed
Fixed #16863 - better handle unique not required custom field redirects
Signed-off-by: snipe <[email protected]>
1 parent f181e0f commit 1881054

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

app/Http/Controllers/Assets/AssetCheckinController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ public function create(Asset $asset, $backto = null) : View | RedirectResponse
4242
return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix'));
4343
}
4444

45-
// Validate custom fields on existing asset
46-
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
45+
// Invoke the validation to see if the audit will complete successfully
46+
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
4747

48-
if ($validator->fails()) {
49-
return redirect()->route('hardware.edit', $asset)
50-
->withErrors($validator);
48+
if ($asset->isInvalid()) {
49+
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
5150
}
5251

5352
$target_option = match ($asset->assigned_type) {

app/Http/Controllers/Assets/AssetCheckoutController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public function create(Asset $asset) : View | RedirectResponse
3737
->with('error', trans('admin/hardware/general.model_invalid_fix'));
3838
}
3939

40-
// Validate custom fields on existing asset
41-
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
40+
// Invoke the validation to see if the audit will complete successfully
41+
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
4242

43-
if ($validator->fails()) {
44-
return redirect()->route('hardware.edit', $asset)
45-
->withErrors($validator);
43+
if ($asset->isInvalid()) {
44+
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
4645
}
46+
4747

4848
if ($asset->availableForCheckout()) {
4949
return view('hardware/checkout', compact('asset'))

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,12 @@ public function audit(Asset $asset): View | RedirectResponse
882882
$this->authorize('audit', Asset::class);
883883
$settings = Setting::getSettings();
884884

885-
// Validate custom fields on existing asset
886-
$validator = Validator::make($asset->toArray(), $asset->customFieldValidationRules());
887885

888-
if ($validator->fails()) {
889-
return redirect()->route('hardware.edit', $asset)
890-
->withErrors($validator);
886+
// Invoke the validation to see if the audit will complete successfully
887+
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
888+
889+
if ($asset->isInvalid()) {
890+
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
891891
}
892892

893893
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();

app/Models/CustomFieldset.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ public function validation_rules()
113113
$rule[] = 'unique_undeleted';
114114
}
115115

116-
array_push($rule, $field->attributes['format']);
116+
if ($field->attributes['format']!='') {
117+
array_push($rule, $field->attributes['format']);
118+
}
119+
117120
$rules[$field->db_column_name()] = $rule;
118121

119122

0 commit comments

Comments
 (0)