mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
prevents deletion of assigned assets in bulk deletion
This commit is contained in:
parent
e814cd5a9e
commit
a534b488b2
|
@ -525,20 +525,25 @@ class BulkAssetsController extends Controller
|
|||
$this->authorize('delete', Asset::class);
|
||||
|
||||
$bulk_back_url = route('hardware.index');
|
||||
|
||||
if ($request->session()->has('bulk_back_url')) {
|
||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||
}
|
||||
$assetIds = $request->get('ids');
|
||||
$assignedAssets = Asset::whereIn('id', $assetIds)->whereNotNull('assigned_to')->get();
|
||||
|
||||
if ($request->filled('ids')) {
|
||||
$assets = Asset::find($request->get('ids'));
|
||||
foreach ($assets as $asset) {
|
||||
$asset->delete();
|
||||
} // endforeach
|
||||
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.delete.success'));
|
||||
// no values given, nothing to update
|
||||
if($assignedAssets->isNotEmpty()) {
|
||||
//if assets are checked out, return a list of asset tags that would need to be checked in first.
|
||||
$assetTags = $assignedAssets->pluck('asset_tag')->implode(', ');
|
||||
return redirect()->route('hardware.index')->with('error', trans_choice('admin/hardware/message.delete.assigned_to_error', $assignedAssets->count(), ['asset_tag' => $assetTags] ));
|
||||
}
|
||||
|
||||
if($assetIds) {
|
||||
Asset::wherein('id', $assetIds)->delete();
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.delete.success'));
|
||||
}
|
||||
// no values given, nothing to update
|
||||
|
||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.delete.nothing_updated'));
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ return [
|
|||
'delete' => [
|
||||
'confirm' => 'Are you sure you wish to delete this asset?',
|
||||
'error' => 'There was an issue deleting the asset. Please try again.',
|
||||
'assigned_to_error' => '{1}Asset Tag: :asset_tag is currently checked out. Check in this device before deletion.|[2,*]Asset Tags: :asset_tag are currently checked out. Check in these devices before deletion.',
|
||||
'nothing_updated' => 'No assets were selected, so nothing was deleted.',
|
||||
'success' => 'The asset was deleted successfully.',
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue