Skip to content

Added the ability to bulk print users #15534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/Http/Controllers/Users/BulkUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\LicenseSeat;
use App\Models\ConsumableAssignment;
use App\Models\Consumable;
use App\Models\Setting;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -76,6 +77,33 @@ public function edit(Request $request)
}
return redirect()->back()->with('success', trans('admin/users/message.password_resets_sent'));

} elseif ($request->input('bulk_actions') == 'print') {
$users = User::query()
->with([
'assets.assetlog',
'assets.assignedAssets.assetlog',
'assets.assignedAssets.defaultLoc',
'assets.assignedAssets.location',
'assets.assignedAssets.model.category',
'assets.defaultLoc',
'assets.location',
'assets.model.category',
'accessories.assetlog',
'accessories.category',
'accessories.manufacturer',
'consumables.assetlog',
'consumables.category',
'consumables.manufacturer',
'licenses.category',
])
->withTrashed()
->findMany($request->input('ids'));

$users->each(fn($user) => $this->authorize('view', $user));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not positive about this since the top of the controller method has $this->authorize('update', User::class);...might end up in a place where the user has access to view users but not update them?

Or maybe I should make this $this->authorize('view', User::class);?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can start with $this->authorize('view', User::class); and add the stronger gates within that faux-router controller method.


return view('users.print')
->with('users', $users)
->with('settings', Setting::getSettings());
}
}

Expand Down
36 changes: 25 additions & 11 deletions app/Http/Controllers/Users/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,23 +597,37 @@ public function getExportUserCsv()
public function printInventory($id)
{
$this->authorize('view', User::class);
if ($user = User::where('id', $id)->withTrashed()->first()) {

$user = User::where('id', $id)
->with([
'assets.assetlog',
'assets.assignedAssets.assetlog',
'assets.assignedAssets.defaultLoc',
'assets.assignedAssets.location',
'assets.assignedAssets.model.category',
'assets.defaultLoc',
'assets.location',
'assets.model.category',
'accessories.assetlog',
'accessories.category',
'accessories.manufacturer',
'consumables.assetlog',
'consumables.category',
'consumables.manufacturer',
'licenses.category',
])
->withTrashed()
->first();

if ($user) {
$this->authorize('view', $user);
$assets = Asset::where('assigned_to', $id)->where('assigned_type', User::class)->with('model', 'model.category')->get();
$accessories = $user->accessories()->get();
$consumables = $user->consumables()->get();

return view('users/print')->with('assets', $assets)
->with('licenses', $user->licenses()->get())
->with('accessories', $accessories)
->with('consumables', $consumables)
->with('show_user', $user)

return view('users.print')
->with('users', [$user])
->with('settings', Setting::getSettings());
}

return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id')));

}

/**
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
'status_label' => 'Status Label',
'status' => 'Status',
'accept_eula' => 'Acceptance Agreement',
'show_or_hide_eulas' => 'Show/Hide EULAs',
'supplier' => 'Supplier',
'suppliers' => 'Suppliers',
'sure_to_delete' => 'Are you sure you wish to delete',
Expand Down
3 changes: 2 additions & 1 deletion resources/views/partials/users-bulk-actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
<option value="delete">{!! trans('general.bulk_checkin_delete') !!}</option>
<option value="merge">{!! trans('general.merge_users') !!}</option>
<option value="bulkpasswordreset">{{ trans('button.send_password_link') }}</option>
<option value="print">{{ trans('admin/users/general.print_assigned') }}</option>
</select>
<button class="btn btn-primary" id="bulkUserEditButton" disabled>{{ trans('button.go') }}</button>
</div>
@endcan
@endif
{{ Form::close() }}
</div>
</div>
Loading
Loading