From fae4ad606867f91f8499694e499e7096f41e11a1 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 24 Feb 2025 10:22:52 -0800 Subject: [PATCH 1/6] prevents parent assets from being deleted --- .../Assets/BulkAssetsController.php | 43 ++++++++++++++++--- .../lang/en-US/admin/hardware/message.php | 3 +- resources/views/notifications.blade.php | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 14e5463ef9..58da5ae790 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -535,14 +535,47 @@ class BulkAssetsController extends Controller return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.delete.nothing_updated')); } - $assignedAssets = Asset::whereIn('id', $assetIds)->whereNotNull('assigned_to')->get(); - if($assignedAssets->isNotEmpty()) { + $parentAssets = Asset::whereIn('id', $assetIds) + ->whereHas('assignedAssets') + ->get(); - //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($bulk_back_url)->with('error', trans_choice('admin/hardware/message.delete.assigned_to_error', $assignedAssets->count(), ['asset_tag' => $assetTags] )); + $assignedAssets = Asset::whereIn('id', $assetIds) + ->whereNotNull('assigned_to') + ->get(); + + $errorMessages = []; + + if ($assignedAssets->isNotEmpty()) { + $assignedTags = $assignedAssets->pluck('asset_tag')->implode(', '); + $errorMessages[] = trans_choice( + 'admin/hardware/message.delete.assigned_to_error', + $assignedAssets->count(), + ['asset_tag' => $assignedTags] + ); } + if ($parentAssets->isNotEmpty()) { + $parentTags = $parentAssets->pluck('asset_tag')->implode(', '); + $errorMessages[] = trans_choice( + 'admin/hardware/message.delete.parent_assigned_error', + $parentAssets->count(), + ['asset_tag' => $parentTags] + ); + } + + if (!empty($errorMessages)) { + // Combine both messages + $combinedErrorMessage = implode('
', $errorMessages); + + return redirect($bulk_back_url)->with('error', $combinedErrorMessage); + } +// if($assignedAssets->isNotEmpty() && $parentAsset->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($bulk_back_url)->with('error', trans_choice('admin/hardware/message.delete.assigned_to_error', $assignedAssets->count(), ['asset_tag' => $assetTags] )); +// } + foreach (Asset::wherein('id', $assetIds)->get() as $asset) { $asset->delete(); } diff --git a/resources/lang/en-US/admin/hardware/message.php b/resources/lang/en-US/admin/hardware/message.php index 605c1fe230..384a83922f 100644 --- a/resources/lang/en-US/admin/hardware/message.php +++ b/resources/lang/en-US/admin/hardware/message.php @@ -72,7 +72,8 @@ 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.', + 'assigned_to_error' => '{1}Asset Tag: :asset_tag is currently checked out. Check in this device before deletion of this asset.|[2,*]Asset Tags: :asset_tag are currently checked out. Check in these devices before deletion of these assets.', + 'parent_assigned_error' => '{1}Asset Tag: :asset_tag currently has items checked out. Check in all items attached before deletion of this asset.|[2,*]Asset Tags: :asset_tag currently have items checked out. Check in these devices before deletion of these assets.', 'nothing_updated' => 'No assets were selected, so nothing was deleted.', 'success' => 'The asset was deleted successfully.', ], diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 7d74e5d043..599c8dd2f5 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -109,7 +109,7 @@ {{ trans('general.error') }}: - {{ $message }} + {!! $message !!} @endif From 99fc11aa6209835bc79f4b9146e87e1b1d11f8b9 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 24 Feb 2025 10:23:38 -0800 Subject: [PATCH 2/6] remove unused code" --- app/Http/Controllers/Assets/BulkAssetsController.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 58da5ae790..72d8bd9083 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -569,12 +569,6 @@ class BulkAssetsController extends Controller return redirect($bulk_back_url)->with('error', $combinedErrorMessage); } -// if($assignedAssets->isNotEmpty() && $parentAsset->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($bulk_back_url)->with('error', trans_choice('admin/hardware/message.delete.assigned_to_error', $assignedAssets->count(), ['asset_tag' => $assetTags] )); -// } foreach (Asset::wherein('id', $assetIds)->get() as $asset) { $asset->delete(); From cf544f9fae502f89178e4808636a1132284b35a5 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 26 Feb 2025 10:36:27 -0800 Subject: [PATCH 3/6] escape asset tags and notification --- .../Controllers/Assets/BulkAssetsController.php | 6 +++--- resources/lang/en-US/admin/hardware/message.php | 4 ++-- resources/views/notifications.blade.php | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 72d8bd9083..b4e0ea8f51 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -550,7 +550,7 @@ class BulkAssetsController extends Controller $errorMessages[] = trans_choice( 'admin/hardware/message.delete.assigned_to_error', $assignedAssets->count(), - ['asset_tag' => $assignedTags] + ['asset_tag' => e($assignedTags)] ); } @@ -559,7 +559,7 @@ class BulkAssetsController extends Controller $errorMessages[] = trans_choice( 'admin/hardware/message.delete.parent_assigned_error', $parentAssets->count(), - ['asset_tag' => $parentTags] + ['asset_tag' => e($parentTags)] ); } @@ -567,7 +567,7 @@ class BulkAssetsController extends Controller // Combine both messages $combinedErrorMessage = implode('
', $errorMessages); - return redirect($bulk_back_url)->with('error', $combinedErrorMessage); + return redirect($bulk_back_url)->with('error-unescaped', $combinedErrorMessage); } foreach (Asset::wherein('id', $assetIds)->get() as $asset) { diff --git a/resources/lang/en-US/admin/hardware/message.php b/resources/lang/en-US/admin/hardware/message.php index 384a83922f..09dc99e8ca 100644 --- a/resources/lang/en-US/admin/hardware/message.php +++ b/resources/lang/en-US/admin/hardware/message.php @@ -72,8 +72,8 @@ 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 of this asset.|[2,*]Asset Tags: :asset_tag are currently checked out. Check in these devices before deletion of these assets.', - 'parent_assigned_error' => '{1}Asset Tag: :asset_tag currently has items checked out. Check in all items attached before deletion of this asset.|[2,*]Asset Tags: :asset_tag currently have items checked out. Check in these devices before deletion of these assets.', + 'assigned_to_error' => 'Asset Tag: :asset_tag is currently checked out. Check in this device before deletion of this asset.|[2,*]Asset Tags: :asset_tag are currently checked out. Check in these devices before deletion of these assets.', + 'parent_assigned_error' => 'Asset Tag: :asset_tag currently has items checked out. Check in all items attached before deletion of this asset.|[2,*]Asset Tags: :asset_tag currently have items checked out. Check in these devices before deletion of these assets.', 'nothing_updated' => 'No assets were selected, so nothing was deleted.', 'success' => 'The asset was deleted successfully.', ], diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 599c8dd2f5..4c62006c55 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -109,10 +109,20 @@ {{ trans('general.error') }}: - {!! $message !!} + {{ $message }} @endif +@if ($message = session()->get('error-unescaped')) +
+
+ + + {{ trans('general.notification_error') }}: + {!! $message !!} +
+
+@endif @if ($messages = session()->get('error_messages')) @@ -169,4 +179,4 @@ {{ $message }} -@endif +@endif \ No newline at end of file From c8ed5d2f96313855f8bc7def451faa4b39a51fec Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 26 Feb 2025 10:39:48 -0800 Subject: [PATCH 4/6] changed icon for error-unescaped to exclamation --- resources/views/notifications.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 4c62006c55..75a6fc93d3 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -117,7 +117,7 @@
- + {{ trans('general.notification_error') }}: {!! $message !!}
From 784aec3cbd5b7282ee0688248e6957db1d961fdc Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 26 Feb 2025 10:51:17 -0800 Subject: [PATCH 5/6] removed logging user without an email from acceptance reminder command --- app/Console/Commands/SendAcceptanceReminder.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index f4ab2c5b68..4ba5d8fea2 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -71,9 +71,6 @@ class SendAcceptanceReminder extends Command $acceptance = $unacceptedAssetGroup[0]['acceptance']; $locale = $acceptance->assignedTo?->locale; $email = $acceptance->assignedTo?->email; - if(!$email){ - $this->info($acceptance->assignedTo?->present()->fullName().' has no email address.'); - } $item_count = $unacceptedAssetGroup->count(); if ($locale && $email) { From e106e8ad2d365f5f3f36cb26b4ea13566d617ada Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 26 Feb 2025 10:52:19 -0800 Subject: [PATCH 6/6] Revert "removed logging user without an email from acceptance reminder command" This reverts commit 784aec3cbd5b7282ee0688248e6957db1d961fdc. --- app/Console/Commands/SendAcceptanceReminder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index 4ba5d8fea2..f4ab2c5b68 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -71,6 +71,9 @@ class SendAcceptanceReminder extends Command $acceptance = $unacceptedAssetGroup[0]['acceptance']; $locale = $acceptance->assignedTo?->locale; $email = $acceptance->assignedTo?->email; + if(!$email){ + $this->info($acceptance->assignedTo?->present()->fullName().' has no email address.'); + } $item_count = $unacceptedAssetGroup->count(); if ($locale && $email) {