A free open source IT asset/license management system
removes undeployables from asset_id array
Godfrey M3cfed72af4bc
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.phpindex cec6f302b1..26ec1206cf 100644--- a/app/Http/Controllers/Assets/BulkAssetsController.php+++ b/app/Http/Controllers/Assets/BulkAssetsController.php@@ -53,9 +53,13 @@ class BulkAssetsController extends Controller$asset_ids = $request->input('ids');if ($request->input('bulk_actions') === 'checkout') {+ $status_check =$this->hasUndeployableStatus($asset_ids);+ if($status_check && $status_check['status'] === true){- if($this->hasUndeployableStatus($asset_ids)){- return redirect()->back()->with('error', trans('admin/hardware/message.undeployable'));+ $asset_tags = implode(', ', array_column($status_check['tags'], 'asset_tag'));+ $asset_ids = $status_check['asset_ids'];++ session()->flash('error', trans('admin/hardware/message.undeployable', ['asset_tags' => $asset_tags]));}$request->session()->flashInput(['selected_assets' => $asset_ids]);@@ -665,14 +669,24 @@ class BulkAssetsController extends Controllerreturn redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success'));}}- public function hasUndeployableStatus (array $asset_ids) : bool+ public function hasUndeployableStatus (array $asset_ids){$undeployable = Asset::whereIn('id', $asset_ids)->undeployable()- ->first();+ ->get();++ $undeployableTags = $undeployable->map(function ($asset) {+ return [+ 'id' => $asset->id,+ 'asset_tag' => $asset->asset_tag,+ ];+ })->toArray();++ $undeployableIds = array_column($undeployableTags, 'id');+ $filtered_ids = array_diff($asset_ids, $undeployableIds);- if($undeployable) {- return true;+ if($undeployable->isNotEmpty()) {+ return ['status' => true, 'tags' => $undeployableTags, 'asset_ids' => $filtered_ids];}return false;}diff --git a/resources/lang/en-US/admin/hardware/message.php b/resources/lang/en-US/admin/hardware/message.phpindex 893f992708..09c459a775 100644--- a/resources/lang/en-US/admin/hardware/message.php+++ b/resources/lang/en-US/admin/hardware/message.php@@ -2,7 +2,7 @@return [- 'undeployable' => 'An asset in your selection for checkout has been marked as currently undeployable. If this status has changed, please update the asset status before checking it out.',+ 'undeployable' => 'The following assets cannot be deployed and have been removed from checkout: :asset_tags','does_not_exist' => 'Asset does not exist.','does_not_exist_var' => 'Asset with tag :asset_tag not found.','no_tag' => 'No asset tag provided.',