A free open source IT asset/license management system
Fixed #19709 - print all on user’s profile
snipeab324bd3284e
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.phpindex f5624f018d..239d12df5a 100755--- a/app/Http/Controllers/ProfileController.php+++ b/app/Http/Controllers/ProfileController.php@@ -228,10 +228,17 @@ class ProfileController extends Controller+ $show_user->assets->flatMap->licenses->count()+ $show_user->assets->flatMap->assignedAccessories->count();+ // Users printing their own inventory always see their own items,+ // regardless of the class-level view permission for each resource.return view('users.print')->with('users', [$show_user])->with('indirectItemsCount', $indirectItemsCount)- ->with('settings', Setting::getSettings());+ ->with('settings', Setting::getSettings())+ ->with('canViewAssets', true)+ ->with('canViewLicenses', true)+ ->with('canViewAccessories', true)+ ->with('canViewConsumables', true)+ ->with('canViewComponents', true);}/**diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.phpindex 63a3681531..4ffb7b2740 100755--- a/app/Http/Controllers/Users/UsersController.php+++ b/app/Http/Controllers/Users/UsersController.php@@ -746,7 +746,12 @@ class UsersController extends Controllerreturn view('users.print')->with('users', [$user])->with('indirectItemsCount', $indirectItemsCount)- ->with('settings', Setting::getSettings());+ ->with('settings', Setting::getSettings())+ ->with('canViewAssets', $canViewAssets)+ ->with('canViewLicenses', $canViewLicenses)+ ->with('canViewAccessories', $canViewAccessories)+ ->with('canViewConsumables', $canViewConsumables)+ ->with('canViewComponents', $canViewComponents);}return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id')));diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.phpindex 15d7075c2b..8bfe2a61e6 100644--- a/resources/views/users/print.blade.php+++ b/resources/views/users/print.blade.php@@ -105,7 +105,7 @@</h3><p></p>{{ trans('admin/users/general.all_assigned_list_generation')}} {{ Helper::getFormattedDateObject(now(), 'datetime', false) }}- @can('view', \App\Models\Asset::class)+ @if ($canViewAssets)@if ($show_user->assets->count() > 0)@php$counter = 1;@@ -176,9 +176,9 @@</tbody></table>@endif- @endcan+ @endif- @can('view', \App\Models\License::class)+ @if ($canViewLicenses)@if ($show_user->directlicenses->count() > 0)<div id="licenses-toolbar"><h4>{{ trans_choice('general.countable.licenses', $show_user->directlicenses->count(), ['count' => $show_user->directlicenses->count()]) }}</h4>@@ -239,10 +239,10 @@@endforeach</table>@endif- @endcan+ @endif- @can('view', \App\Models\Accessory::class)+ @if ($canViewAccessories)@if ($show_user->accessories->count() > 0)<div id="accessories-toolbar"><h4>{{ trans_choice('general.countable.accessories', $show_user->accessories->count(), ['count' => $show_user->accessories->count()]) }}</h4>@@ -306,9 +306,9 @@@endforeach</table>@endif- @endcan+ @endif- @can('view', \App\Models\Consumable::class)+ @if ($canViewConsumables)@if ($show_user->consumables->count() > 0)<div id="consumables-toolbar"><h4>{{ trans_choice('general.countable.consumables', $show_user->consumables->count(), ['count' => $show_user->consumables->count()]) }}</h4>@@ -372,7 +372,7 @@@endforeach</table>@endif- @endcan+ @endif@if(($indirectItemsCount ?? 0) > 0 && $settings->show_assigned_assets)<div id="indirect-assignments-toolbar">@@ -418,7 +418,7 @@$indirectAssignmentsCounter++@endphp@endforeach- @can('view', \App\Models\License::class)+ @if ($canViewLicenses)@foreach ($asset->licenses as $indirectLicense)@if($indirectLicense)<tr>@@ -433,8 +433,8 @@$indirectAssignmentsCounter ++@endphp@endforeach- @endcan- @can('view', \App\Models\Component::class)+ @endif+ @if ($canViewComponents)@foreach ($asset->components as $component)@if($component)<tr>@@ -449,8 +449,8 @@$indirectAssignmentsCounter ++@endphp@endforeach- @endcan- @can('view', \App\Models\Accessory::class)+ @endif+ @if ($canViewAccessories)@foreach ($asset->assignedAccessories as $indirectAccessory)@if($indirectAccessory)<tr>@@ -465,7 +465,7 @@$indirectAssignmentsCounter ++@endphp@endforeach- @endcan+ @endif@endforeach</table>@endifdiff --git a/tests/Feature/Account/PrintInventoryTest.php b/tests/Feature/Account/PrintInventoryTest.phpnew file mode 100644index 0000000000..2e108ee327--- /dev/null+++ b/tests/Feature/Account/PrintInventoryTest.php@@ -0,0 +1,24 @@+<?php++namespace Tests\Feature\Account;++use App\Models\Asset;+use App\Models\User;+use Tests\TestCase;++class PrintInventoryTest extends TestCase+{+ public function test_regular_user_without_view_assets_permission_sees_own_assets(): void+ {+ // Regression coverage for GH #19709: a user with no view-assets+ // permission would see an empty print page for their own inventory,+ // because the blade class-level @can gate blocked their own items.+ $user = User::factory()->create();+ $asset = Asset::factory()->assignedToUser($user)->create();++ $this->actingAs($user)+ ->get(route('profile.print'))+ ->assertOk()+ ->assertSee($asset->asset_tag);+ }+}