diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index 9ded0ee8ec..119da3f7c4 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -15,6 +15,7 @@ use App\Models\ConsumableAssignment; use App\Models\Consumable; use App\Models\Setting; use App\Models\User; +use App\Notifications\CurrentInventory; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Collection; @@ -52,6 +53,28 @@ class BulkUsersController extends Controller return view('users/bulk-edit', compact('users')) ->with('groups', Group::pluck('name', 'id')); + // bulk send assigned inventory + } elseif ($request->input('bulk_actions') == 'send_assigned') { + $this->authorize('update', User::class); + + $users_without_email = 0; + foreach ($users as $user) { + if (empty($user->email)) { + $users_without_email++; + } else { + $user->notify((new CurrentInventory($user))); + } + } + + if ($users_without_email == 0) { + return redirect()->back()->with('success', trans_choice('admin/users/general.users_notified', $users->count())); + } else { + return redirect()->back()->with('warning', trans_choice('admin/users/general.users_notified_warning', $users->count(), ['no_email' => $users_without_email])); + } + + + + // bulk delete, display the bulk delete confirmation form } elseif ($request->input('bulk_actions') == 'delete') { $this->authorize('delete', User::class); diff --git a/resources/lang/en-US/admin/users/general.php b/resources/lang/en-US/admin/users/general.php index b097ccec69..14f36cf151 100644 --- a/resources/lang/en-US/admin/users/general.php +++ b/resources/lang/en-US/admin/users/general.php @@ -19,6 +19,8 @@ return [ 'print_assigned' => 'Print All Assigned', 'email_assigned' => 'Email List of All Assigned', 'user_notified' => 'User has been emailed a list of their currently assigned items.', + 'users_notified' => 'The user has been emailed a list of their currently assigned items.|:count users have been emailed a list of their currently assigned items.', + 'users_notified_warning' => ':count user has been emailed a list of their currently assigned items, however :no_email users did not have an email address so could not be emailed.|:count users have been emailed a list of their currently assigned items, however :no_email user(s) did not have an email address so could not be emailed.', 'auto_assign_label' => 'Include this user when auto-assigning eligible licenses', 'auto_assign_help' => 'Skip this user in auto assignment of licenses', 'software_user' => 'Software Checked out to :name', diff --git a/resources/views/partials/users-bulk-actions.blade.php b/resources/views/partials/users-bulk-actions.blade.php index 4d93d88f3a..4b610c187d 100644 --- a/resources/views/partials/users-bulk-actions.blade.php +++ b/resources/views/partials/users-bulk-actions.blade.php @@ -18,6 +18,7 @@ @can('update', \App\Models\User::class) + @endcan @can('delete', \App\Models\User::class)