Skip to content

Commit cca46ea

Browse files
authored
Merge pull request #16292 from snipe/add_email_list_assigned_to_bulk
Added ability to send user inventory via bulk UI
2 parents 056fbef + bde0345 commit cca46ea

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

app/Http/Controllers/Users/BulkUsersController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use App\Models\Consumable;
1616
use App\Models\Setting;
1717
use App\Models\User;
18+
use App\Notifications\CurrentInventory;
1819
use Carbon\Carbon;
1920
use Illuminate\Http\Request;
2021
use Illuminate\Support\Collection;
@@ -52,6 +53,28 @@ public function edit(Request $request)
5253
return view('users/bulk-edit', compact('users'))
5354
->with('groups', Group::pluck('name', 'id'));
5455

56+
// bulk send assigned inventory
57+
} elseif ($request->input('bulk_actions') == 'send_assigned') {
58+
$this->authorize('update', User::class);
59+
60+
$users_without_email = 0;
61+
foreach ($users as $user) {
62+
if (empty($user->email)) {
63+
$users_without_email++;
64+
} else {
65+
$user->notify((new CurrentInventory($user)));
66+
}
67+
}
68+
69+
if ($users_without_email == 0) {
70+
return redirect()->back()->with('success', trans_choice('admin/users/general.users_notified', $users->count()));
71+
} else {
72+
return redirect()->back()->with('warning', trans_choice('admin/users/general.users_notified_warning', $users->count(), ['no_email' => $users_without_email]));
73+
}
74+
75+
76+
77+
5578
// bulk delete, display the bulk delete confirmation form
5679
} elseif ($request->input('bulk_actions') == 'delete') {
5780
$this->authorize('delete', User::class);

resources/lang/en-US/admin/users/general.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
'print_assigned' => 'Print All Assigned',
2020
'email_assigned' => 'Email List of All Assigned',
2121
'user_notified' => 'User has been emailed a list of their currently assigned items.',
22+
'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.',
23+
'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.',
2224
'auto_assign_label' => 'Include this user when auto-assigning eligible licenses',
2325
'auto_assign_help' => 'Skip this user in auto assignment of licenses',
2426
'software_user' => 'Software Checked out to :name',

resources/views/partials/users-bulk-actions.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class="form-inline"
1818

1919
@can('update', \App\Models\User::class)
2020
<option value="edit">{{ trans('general.bulk_edit') }}</option>
21+
<option value="send_assigned">{{ trans('admin/users/general.email_assigned') }}</option>
2122
@endcan
2223

2324
@can('delete', \App\Models\User::class)

0 commit comments

Comments
 (0)