Skip to content

Commit 1434522

Browse files
authored
Merge pull request #15912 from marcusmoore/bug/harden-checkout-validation-v2
Harden asset checkout validation
2 parents 23af5fb + 1d0d148 commit 1434522

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/Http/Requests/AssetCheckoutRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function rules()
2424
$settings = \App\Models\Setting::getSettings();
2525

2626
$rules = [
27-
'assigned_user' => 'required_without_all:assigned_asset,assigned_location',
28-
'assigned_asset' => 'required_without_all:assigned_user,assigned_location',
29-
'assigned_location' => 'required_without_all:assigned_user,assigned_asset',
27+
'assigned_user' => 'numeric|nullable|required_without_all:assigned_asset,assigned_location',
28+
'assigned_asset' => 'numeric|nullable|required_without_all:assigned_user,assigned_location',
29+
'assigned_location' => 'numeric|nullable|required_without_all:assigned_user,assigned_asset',
3030
'status_id' => 'exists:status_labels,id,deployable,1',
3131
'checkout_to_type' => 'required|in:asset,location,user',
3232
'checkout_at' => [

tests/Feature/Checkouts/Ui/AssetCheckoutTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,23 @@ public function testAssetCanBeCheckedOut($data)
183183
$asset = Asset::factory()->create();
184184
$admin = User::factory()->checkoutAssets()->create();
185185

186+
$defaultFieldsAlwaysIncludedInUIFormSubmission = [
187+
'assigned_user' => null,
188+
'assigned_asset' => null,
189+
'assigned_location' => null,
190+
];
191+
186192
$this->actingAs($admin)
187-
->post(route('hardware.checkout.store', $asset), [
193+
->post(route('hardware.checkout.store', $asset), array_merge($defaultFieldsAlwaysIncludedInUIFormSubmission, [
188194
'checkout_to_type' => $type,
189-
'assigned_' . $type => $target->id,
195+
// overwrite the value from the default fields set above
196+
'assigned_' . $type => (string) $target->id,
190197
'name' => 'Changed Name',
191-
'status_id' => $newStatus->id,
198+
'status_id' => (string) $newStatus->id,
192199
'checkout_at' => '2024-03-18',
193200
'expected_checkin' => '2024-03-28',
194201
'note' => 'An awesome note',
195-
]);
202+
]));
196203

197204
$asset->refresh();
198205
$this->assertTrue($asset->assignedTo()->is($target));

0 commit comments

Comments
 (0)