From 426c81aea2bb014ad0bf79ec61e0de8adf372e81 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 12 Mar 2025 10:33:59 -0700 Subject: [PATCH 1/3] prevents bulk checkout of undeployable assets --- app/Http/Controllers/Assets/BulkAssetsController.php | 8 ++++++++ resources/lang/en-US/admin/hardware/form.php | 1 + 2 files changed, 9 insertions(+) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 9e8ddfd08f08..c55cfc57ccc9 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -53,6 +53,14 @@ public function edit(Request $request) : View | RedirectResponse $asset_ids = $request->input('ids'); if ($request->input('bulk_actions') === 'checkout') { + $undeployable_assets = Asset::whereIn('id', $asset_ids) + ->whereHas('assetStatus', function ($query){ + $query->where('deployable', 0); + }) + ->get(); + if($undeployable_assets->count() > 0) { + return redirect()->back()->with('error', trans_choice('admin/hardware/form.bulk_asset_undeployable', $undeployable_assets->count())); + } $request->session()->flashInput(['selected_assets' => $asset_ids]); return redirect()->route('hardware.bulkcheckout.show'); } diff --git a/resources/lang/en-US/admin/hardware/form.php b/resources/lang/en-US/admin/hardware/form.php index fab19fea13bc..2dafee753325 100644 --- a/resources/lang/en-US/admin/hardware/form.php +++ b/resources/lang/en-US/admin/hardware/form.php @@ -56,6 +56,7 @@ 'asset_location_update_actual' => 'Update only actual location', 'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.', 'asset_not_deployable_checkin' => 'That asset status is not deployable. Using this status label will checkin the asset.', + 'bulk_asset_undeployable' => 'Asset in this bulk checkout request is undeployable.|[2,*]Assets in this bulk checkout request are undeployable.', 'asset_deployable' => 'This asset can be checked out.', 'processing_spinner' => 'Processing... (This might take a bit of time on large files)', 'optional_infos' => 'Optional Information', From bc235b14f0516bdf57b695a60fc575523bd3571a Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 12 Mar 2025 11:35:44 -0700 Subject: [PATCH 2/3] update query to match undeployable scope --- app/Http/Controllers/Assets/BulkAssetsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index c55cfc57ccc9..af866eac7759 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -55,7 +55,9 @@ public function edit(Request $request) : View | RedirectResponse if ($request->input('bulk_actions') === 'checkout') { $undeployable_assets = Asset::whereIn('id', $asset_ids) ->whereHas('assetStatus', function ($query){ - $query->where('deployable', 0); + $query->where('deployable', 0) + ->where('archived', 0) + ->where('pending', 0); }) ->get(); if($undeployable_assets->count() > 0) { From cbeda81b37b6447facf6560b48fb9334db6cada3 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 15 Apr 2025 11:22:42 -0700 Subject: [PATCH 3/3] changed undeployable_assets query --- app/Http/Controllers/Assets/BulkAssetsController.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index af866eac7759..dc9d96e411c4 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -53,13 +53,8 @@ public function edit(Request $request) : View | RedirectResponse $asset_ids = $request->input('ids'); if ($request->input('bulk_actions') === 'checkout') { - $undeployable_assets = Asset::whereIn('id', $asset_ids) - ->whereHas('assetStatus', function ($query){ - $query->where('deployable', 0) - ->where('archived', 0) - ->where('pending', 0); - }) - ->get(); + $undeployable_assets = Asset::findMany($asset_ids)->filter(fn(Asset $asset) => !$asset->availableForCheckout()); + if($undeployable_assets->count() > 0) { return redirect()->back()->with('error', trans_choice('admin/hardware/form.bulk_asset_undeployable', $undeployable_assets->count())); }