From b7c7e6c6239b9907559b1bdab9d022aeb3e7733f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 17:56:58 -0700 Subject: [PATCH 1/6] Added/updated language strings Signed-off-by: snipe --- resources/lang/en/general.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 9b1380f2557f..43e9e4fbe29a 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -37,7 +37,7 @@ 'bulk_edit' => 'Bulk Edit', 'bulk_delete' => 'Bulk Delete', 'bulk_actions' => 'Bulk Actions', - 'bulk_checkin_delete' => 'Bulk Checkin & Delete', + 'bulk_checkin_delete' => 'Bulk Checkin Items from Users', 'bystatus' => 'by Status', 'cancel' => 'Cancel', 'categories' => 'Categories', @@ -365,5 +365,9 @@ 'backup_delete_not_allowed' => 'Deleting backups has been disabled in the .env file. Contact support or your systems administrator.', 'additional_files' => 'Additional Files', 'shitty_browser' => 'No signature detected. If you are using an older browser, please use a more modern browser to complete your asset acceptance.', + 'bulk_soft_delete' =>'Also soft-delete these users. Their asset history will remain intact unless/until you purge deleted records in the Admin Settings.', + 'bulk_checkin_delete_success' => 'Your selected users have been deleted and their items have been checked in.', + 'bulk_checkin_success' => 'The items for the selected users have been checked in.', + ]; \ No newline at end of file From 7313bca4039581b3bda045a6df1c2c7b9d0c4dba Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 17:57:19 -0700 Subject: [PATCH 2/6] Checkin without deleting Signed-off-by: snipe --- .../Controllers/Users/BulkUsersController.php | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index cd6d67983a92..d07d25f543e0 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -5,10 +5,13 @@ use App\Helpers\Helper; use App\Http\Controllers\Controller; use App\Models\Accessory; +use App\Models\License; use App\Models\Actionlog; use App\Models\Asset; use App\Models\Group; use App\Models\LicenseSeat; +use App\Models\ConsumableAssignment; +use App\Models\Consumable; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -162,13 +165,11 @@ public function destroy(Request $request) if ((! $request->filled('ids')) || (count($request->input('ids')) == 0)) { return redirect()->back()->with('error', 'No users selected'); } - if ((! $request->filled('status_id')) || ($request->input('status_id') == '')) { - return redirect()->route('users.index')->with('error', 'No status selected'); - } if (config('app.lock_passwords')) { return redirect()->route('users.index')->with('error', 'Bulk delete is not enabled in this installation'); } + $user_raw_array = request('ids'); if (($key = array_search(Auth::id(), $user_raw_array)) !== false) { @@ -179,11 +180,18 @@ public function destroy(Request $request) $assets = Asset::whereIn('assigned_to', $user_raw_array)->where('assigned_type', \App\Models\User::class)->get(); $accessories = DB::table('accessories_users')->whereIn('assigned_to', $user_raw_array)->get(); $licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get(); + $consumables = DB::table('consumables_users')->whereIn('assigned_to', $user_raw_array)->get(); + + if ((($assets->count() > 0) && ((!$request->filled('status_id')) || ($request->input('status_id') == '')))) { + return redirect()->route('users.index')->with('error', 'No status selected'); + } $this->logItemCheckinAndDelete($assets, Asset::class); $this->logItemCheckinAndDelete($accessories, Accessory::class); - $this->logItemCheckinAndDelete($licenses, LicenseSeat::class); + $this->logItemCheckinAndDelete($licenses, License::class); + $this->logItemCheckinAndDelete($consumables, Consumable::class); + Asset::whereIn('id', $assets->pluck('id'))->update([ 'status_id' => e(request('status_id')), @@ -193,13 +201,26 @@ public function destroy(Request $request) LicenseSeat::whereIn('id', $licenses->pluck('id'))->update(['assigned_to' => null]); + ConsumableAssignment::whereIn('id', $consumables->pluck('id'))->delete(); + foreach ($users as $user) { + + $user->consumables()->sync([]); $user->accessories()->sync([]); - $user->delete(); + if ($request->input('delete_user')=='1') { + $user->delete(); + } + } - return redirect()->route('users.index')->with('success', 'Your selected users have been deleted and their assets have been updated.'); + $msg = trans('general.bulk_checkin_success'); + if ($request->input('delete_user')=='1') { + $msg = trans('general.bulk_checkin_delete_success'); + } + + + return redirect()->route('users.index')->with('success', $msg); } /** @@ -217,7 +238,7 @@ protected function logItemCheckinAndDelete($items, $itemType) $logAction->target_id = $item->assigned_to; $logAction->target_type = User::class; $logAction->user_id = Auth::id(); - $logAction->note = 'Bulk checkin items and delete user'; + $logAction->note = 'Bulk checkin items'; $logAction->logaction('checkin from'); } } From 32010d5387ea7287bceefc7215e12adbee604aea Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 17:57:27 -0700 Subject: [PATCH 3/6] Updated language strings Signed-off-by: snipe --- resources/lang/en/admin/users/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/users/general.php b/resources/lang/en/admin/users/general.php index c77ff8f8c731..daa568e8bfc9 100644 --- a/resources/lang/en/admin/users/general.php +++ b/resources/lang/en/admin/users/general.php @@ -34,7 +34,7 @@ 'admin_permission_warning' => 'Only users with admins rights or greater may grant a user admin access.', 'remove_group_memberships' => 'Remove Group Memberships', 'warning_deletion' => 'WARNING:', - 'warning_deletion_information' => 'You are about to delete the :count user(s) listed below. Super admin names are highlighted in red.', + 'warning_deletion_information' => 'You are about to checkin ALL items from the :count user(s) listed below. Super admin names are highlighted in red.', 'update_user_assets_status' => 'Update all assets for these users to this status', 'checkin_user_properties' => 'Check in all properties associated with these users', 'remote_label' => 'This is a remote user', From 458d61fafebdb5a870bb1e7a480b11af3282e340 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 17:57:39 -0700 Subject: [PATCH 4/6] Front-end updates for checkin without delete Signed-off-by: snipe --- .../views/users/confirm-bulk-delete.blade.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/resources/views/users/confirm-bulk-delete.blade.php b/resources/views/users/confirm-bulk-delete.blade.php index bdc084fdea56..505a4cb98f93 100644 --- a/resources/views/users/confirm-bulk-delete.blade.php +++ b/resources/views/users/confirm-bulk-delete.blade.php @@ -42,6 +42,7 @@ {{ trans('general.assets') }} {{ trans('general.accessories') }} {{ trans('general.licenses') }} + {{ trans('general.consumables') }} @@ -49,14 +50,14 @@ isSuperUser() ? ' class="danger"':'') !!}> @if (Auth::id()!=$user->id) - + @else - + @endif - id==$user->id ? ' style="text-decoration: line-through"' : '') }}> + id==$user->id ? ' style="text-decoration: line-through"' : '') !!}> {{ $user->present()->fullName() }} ({{ $user->username }}) {{ (Auth::id()==$user->id ? ' (cannot delete yourself)' : '') }} @@ -77,19 +78,26 @@ {{ number_format($user->licenses()->count()) }} + + {{ number_format($user->consumables()->count()) }} + @endforeach + - + {{ Form::select('status_id', $statuslabel_list , Request::old('status_id'), array('class'=>'select2', 'style'=>'width:250px')) }} - + - - + + From 25cc46e416613c1b9ea033caf62225c291f2f9c6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 18:01:41 -0700 Subject: [PATCH 5/6] Fixed button string Signed-off-by: snipe --- resources/lang/en/button.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/button.php b/resources/lang/en/button.php index 1e44af7d1a74..22821b815716 100644 --- a/resources/lang/en/button.php +++ b/resources/lang/en/button.php @@ -4,7 +4,7 @@ 'actions' => 'Actions', 'add' => 'Add New', 'cancel' => 'Cancel', - 'checkin_and_delete' => 'Checkin & Delete User', + 'checkin_and_delete' => 'Checkin All / Delete User', 'delete' => 'Delete', 'edit' => 'Edit', 'restore' => 'Restore', From a1fe2a8d58725e4626decd908c11d88d2f464af6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 20 Jul 2022 18:01:55 -0700 Subject: [PATCH 6/6] Fixed translation reference Signed-off-by: snipe --- resources/views/users/confirm-bulk-delete.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/users/confirm-bulk-delete.blade.php b/resources/views/users/confirm-bulk-delete.blade.php index 505a4cb98f93..d5dcac3e1371 100644 --- a/resources/views/users/confirm-bulk-delete.blade.php +++ b/resources/views/users/confirm-bulk-delete.blade.php @@ -26,7 +26,7 @@ @if (config('app.lock_passwords'))
-

{{ trans('feature_disabled') }}

+

{{ trans('general.feature_disabled') }}

@endif