Skip to content

A free open source IT asset/license management system

Fixed #19809 - link Needs Attention to specific views

sniped3f25fe36e3e
diff --git a/app/Helpers/IconHelper.php b/app/Helpers/IconHelper.php
index 53025c8b0d..9c4f7e835a 100644
--- a/app/Helpers/IconHelper.php
+++ b/app/Helpers/IconHelper.php
@@ -110,6 +110,10 @@ class IconHelper
case 'request':
case 'requested':
return 'fa-solid fa-bell-concierge';
+ case 'pending-requests':
+ return 'fa-solid fa-boxes-packing';
+ case 'offboarding':
+ return 'fa-solid fa-door-open';
case 'fulfill_multiple':
return 'fa-solid fa-arrows-down-to-people';
case 'reports':
diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php
index 93b8bc399a..fd57bed1c3 100644
--- a/app/Http/Controllers/Api/UsersController.php
+++ b/app/Http/Controllers/Api/UsersController.php
@@ -301,6 +301,30 @@ class UsersController extends Controller
$users = $users->where('users.end_date', '=', $request->input('end_date'));
}
+ if ($request->filled('end_date_within')) {
+ // Window filter for the dashboard's offboarding tile. Range
+ // comparison instead of whereDate so the index on
+ // users.end_date (added in the 2026_08_14_170000 migration)
+ // can actually be used.
+ $days = (int) $request->input('end_date_within');
+ $users = $users->whereBetween('users.end_date', [
+ now()->startOfDay(),
+ now()->addDays($days)->endOfDay(),
+ ]);
+ }
+
+ if ($request->boolean('with_assignments')) {
+ // Narrow to users who still hold at least one assigned
+ // item. Matches the NeedsAttention widget's offboarding
+ // count so the tile's click-through lands on the same set.
+ $users = $users->where(function ($query) {
+ $query->has('assets')
+ ->orHas('licenses')
+ ->orHas('accessories')
+ ->orHas('consumables');
+ });
+ }
+
if ($request->filled('assets_count')) {
$users->has('assets', '=', $request->input('assets_count'));
}
diff --git a/app/Livewire/NeedsAttention.php b/app/Livewire/NeedsAttention.php
index 618d5542da..a5ecbc7243 100644
--- a/app/Livewire/NeedsAttention.php
+++ b/app/Livewire/NeedsAttention.php
@@ -16,6 +16,7 @@ use App\Models\Consumable;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Maintenance;
+use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
@@ -67,6 +68,12 @@ class NeedsAttention extends Component
public int $usersOffboardingSoon = 0;
+ // Days window for the offboarding tile. Fixed at 30 since there's
+ // no admin-level "offboarding alert" setting the way there is for
+ // licenses. The Blade link forwards this to users.index so the
+ // destination filter matches the count.
+ public const OFFBOARDING_DAYS = 30;
+
public function boot(): void
{
// Matches the DashboardController::index gate. Without this a
@@ -80,7 +87,8 @@ class NeedsAttention extends Component
public function mount(): void
{
$todayStart = now()->startOfDay();
- $inThirtyDays = now()->addDays(30)->endOfDay();
+ $offboardingWindow = now()->addDays(self::OFFBOARDING_DAYS)->endOfDay();
+ $licenseExpiryDays = (int) (Setting::getSettings()->alert_interval ?: 30);
// Every count is gated by the caller's per-type view
// permission. A non-admin who reaches this widget through the
@@ -105,11 +113,28 @@ class NeedsAttention extends Component
}
if (Gate::allows('view', License::class)) {
- $this->licensesExpiringSoon = License::whereBetween('expiration_date', [$todayStart, $inThirtyDays])->count();
+ // Reuses the same scope the admin License index uses for
+ // ?status=expiring, so clicking the tile lands on the same
+ // row set that the count reflects. The scope keys off the
+ // alert_interval setting (default 30 days) rather than a
+ // widget-local constant, so the two can't drift.
+ $this->licensesExpiringSoon = License::expiringLicenses($licenseExpiryDays)->count();
}
if (Gate::allows('view', User::class)) {
- $this->usersOffboardingSoon = User::whereBetween('end_date', [$todayStart, $inThirtyDays])->count();
+ // Users with end_date in the window AND at least one
+ // assigned item. Someone offboarding with nothing on their
+ // record doesn't need IT's attention. Matches the
+ // ?with_assignments=1 filter the tile's link forwards to
+ // users.index.
+ $this->usersOffboardingSoon = User::whereBetween('end_date', [$todayStart, $offboardingWindow])
+ ->where(function ($query) {
+ $query->has('assets')
+ ->orHas('licenses')
+ ->orHas('accessories')
+ ->orHas('consumables');
+ })
+ ->count();
}
// Pending checkout acceptances. whereHasMorph applies each
diff --git a/app/Providers/BreadcrumbsServiceProvider.php b/app/Providers/BreadcrumbsServiceProvider.php
index cefbd03a5a..d69094d22d 100644
--- a/app/Providers/BreadcrumbsServiceProvider.php
+++ b/app/Providers/BreadcrumbsServiceProvider.php
@@ -52,6 +52,12 @@ class BreadcrumbsServiceProvider extends ServiceProvider
->push(trans('general.'.strtolower(e($statusType))), route('hardware.index', ['status_type' => $statusType]))
);
+ } elseif (request()->is('hardware*') && request()->boolean('past_eol')) {
+ Breadcrumbs::for('hardware.index', fn (Trail $trail) => $trail->parent('home', route('home'))
+ ->push(trans('general.assets'), route('hardware.index'))
+ ->push(trans('general.past_eol'), route('hardware.index', ['past_eol' => 1]))
+ );
+
} else {
Breadcrumbs::for('hardware.index', fn (Trail $trail) => $trail->parent('home', route('home'))
->push(trans('general.assets'), route('hardware.index'))
@@ -619,6 +625,11 @@ class BreadcrumbsServiceProvider extends ServiceProvider
->push(trans('general.users'), route('users.index'))
->push(trans('general.login_enabled'), route('users.index'))
);
+ } elseif ((request()->is('users*')) && request()->filled('end_date_within')) {
+ Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
+ ->push(trans('general.users'), route('users.index'))
+ ->push(trans('general.offboarding_soon'), route('users.index'))
+ );
} else {
Breadcrumbs::for('users.index', fn (Trail $trail) => $trail->parent('home', route('home'))
->push(trans('general.users'), route('users.index'))
diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php
index 5e9ae01683..4a29aa1ae0 100644
--- a/resources/lang/en-US/general.php
+++ b/resources/lang/en-US/general.php
@@ -126,9 +126,9 @@ return [
'dashboard_overdue_maintenances' => 'Maintenances overdue',
'dashboard_unaccepted_assets' => 'Unaccepted acceptances',
'dashboard_pending_requests' => 'Open checkout requests',
- 'dashboard_licenses_expiring_soon' => 'Licenses expiring in 30 days',
+ 'dashboard_licenses_expiring_soon' => 'Licenses expiring soon',
'dashboard_assets_past_eol' => 'Assets past EOL',
- 'dashboard_users_offboarding_soon' => 'Employees offboarding in 30 days',
+ 'dashboard_users_offboarding_soon' => 'Employees offboarding soon (with assignments)',
'dashboard_low_stock_empty' => 'Nothing below its minimum quantity threshold.',
'dashboard_low_stock_help' => 'Items show here when remaining quantity falls below the item\'s minimum plus the site-wide alert threshold (currently :threshold), set in Notifications settings.',
'dashboard_activity_empty' => 'No recent activity yet.',
@@ -318,9 +318,11 @@ return [
'edit_note' => 'Edit Note',
'note_deleted' => 'Note Deleted',
'delete_note' => 'Delete Note',
+ 'offboarding_soon' => 'Offboarding Soon',
'order_number' => 'Order Number',
'orders' => 'Orders',
'only_deleted' => 'Only Deleted Assets',
+ 'past_eol' => 'Past EOL',
'page_menu' => 'Showing _MENU_ items',
'page_error' => 'Could not determine previous page. Redirected to homepage.',
'pagination_info' => 'Showing _START_ to _END_ of _TOTAL_ items',
diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php
index eed6fecd93..fa67af0b2b 100644
--- a/resources/views/layouts/default.blade.php
+++ b/resources/views/layouts/default.blade.php
@@ -497,6 +497,13 @@
</li>
@endcan
+ <li id="past-eol-sidenav-option"{!! (request()->is('hardware') && request()->boolean('past_eol') ? ' class="active" aria-current="page"' : '') !!}>
+ <a href="{{ route('hardware.index', ['past_eol' => 1]) }}">
+ <x-icon type="asset" class="text-red fa-fw"/>
+ {{ trans('general.past_eol') }}
+ </a>
+ </li>
+
<li class="divider">&nbsp;</li>
@can('checkin', \App\Models\Asset::class)
<li{!! (request()->is('hardware/quickscancheckin') ? ' class="active" aria-current="page"' : '') !!}>
@@ -652,6 +659,12 @@
{{ trans('general.login_disabled') }}
</a>
</li>
+ <li class="{{ (request()->is('users') && request()->filled('end_date_within')) ? 'active' : '' }}" id="users-sidenav-offboarding">
+ <a href="{{ route('users.index', ['end_date_within' => \App\Livewire\NeedsAttention::OFFBOARDING_DAYS, 'with_assignments' => 1]) }}">
+ <x-icon type="offboarding" class="text-warning fa-fw"/>
+ {{ trans('general.offboarding_soon') }}
+ </a>
+ </li>
</ul>
</li>
@endcan
diff --git a/resources/views/livewire/needs-attention.blade.php b/resources/views/livewire/needs-attention.blade.php
index e454396403..af72e1da9e 100644
--- a/resources/views/livewire/needs-attention.blade.php
+++ b/resources/views/livewire/needs-attention.blade.php
@@ -18,7 +18,7 @@
@can('audit', \App\Models\Asset::class)
<li class="list-group-item">
<a href="{{ route('assets.audit.due') }}">
- <x-icon type="asset" class="fa-fw"/>
+ <x-icon type="audit" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.dashboard_overdue_audits') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($overdueAudits) }}</span>
</a>
@@ -26,8 +26,12 @@
@endcan
@can('checkin', \App\Models\Asset::class)
<li class="list-group-item">
- <a href="{{ route('assets.checkins.due') }}">
- <x-icon type="asset" class="fa-fw"/>
+ {{-- #overdue hash preselects the "overdue" tab via
+ snipeit.js's deep-link handler, so the landing
+ view matches the count semantics. Default tab
+ is "due" (upcoming), not overdue. --}}
+ <a href="{{ route('assets.checkins.due').'#overdue' }}">
+ <x-icon type="due" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.dashboard_overdue_checkins') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($overdueCheckins) }}</span>
</a>
@@ -55,7 +59,7 @@
@can('canCheckoutAtLeastOneItemType')
<li class="list-group-item">
<a href="{{ route('requests.index') }}">
- <i class="fa-solid fa-boxes-packing fa-fw" aria-hidden="true"></i>
+ <x-icon type="pending-requests" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.pending_requests') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($pendingRequestsCount) }}</span>
</a>
@@ -65,7 +69,7 @@
@can('view', \App\Models\Asset::class)
<li class="list-group-item">
<a href="{{ $assetsPastEol > 0 ? route('hardware.index', ['past_eol' => 1]) : route('hardware.index') }}">
- <x-icon type="asset" class="fa-fw"/>
+ <x-icon type="due" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.dashboard_assets_past_eol') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($assetsPastEol) }}</span>
</a>
@@ -80,7 +84,7 @@
@endcan
@can('view', \App\Models\License::class)
<li class="list-group-item">
- <a href="{{ route('licenses.index') }}">
+ <a href="{{ route('licenses.index', ['status' => 'expiring']) }}">
<x-icon type="license" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.dashboard_licenses_expiring_soon') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($licensesExpiringSoon) }}</span>
@@ -89,8 +93,8 @@
@endcan
@can('view', \App\Models\User::class)
<li class="list-group-item">
- <a href="{{ route('users.index') }}">
- <x-icon type="users" class="fa-fw"/>
+ <a href="{{ route('users.index', ['end_date_within' => \App\Livewire\NeedsAttention::OFFBOARDING_DAYS, 'with_assignments' => 1]) }}">
+ <x-icon type="offboarding" class="fa-fw"/>
<span class="dashboard-attention-label">{{ trans('general.dashboard_users_offboarding_soon') }}</span>
<span class="badge dashboard-attention-count">{{ number_format($usersOffboardingSoon) }}</span>
</a>
diff --git a/resources/views/users/index.blade.php b/resources/views/users/index.blade.php
index 414af8fe8b..6f21047ef3 100755
--- a/resources/views/users/index.blade.php
+++ b/resources/views/users/index.blade.php
@@ -39,6 +39,8 @@
'admins' => is_scalar(request('admins')) ? request('admins') : null,
'superadmins' => is_scalar(request('superadmins')) ? request('superadmins') : null,
'activated' => is_scalar(request('activated')) ? request('activated') : null,
+ 'end_date_within' => is_scalar(request('end_date_within')) ? (int) request('end_date_within') : null,
+ 'with_assignments' => request()->boolean('with_assignments') ? 1 : null,
])"/>
</x-box>
<x-shiftclick/>
diff --git a/tests/Feature/Livewire/NeedsAttentionTest.php b/tests/Feature/Livewire/NeedsAttentionTest.php
index c4b65b5b7f..e175a23dd7 100644
--- a/tests/Feature/Livewire/NeedsAttentionTest.php
+++ b/tests/Feature/Livewire/NeedsAttentionTest.php
@@ -239,6 +239,50 @@ class NeedsAttentionTest extends TestCase implements TestsFullMultipleCompaniesS
->assertSet('pendingRequestsCount', 1);
}
+ public function test_users_offboarding_count_requires_at_least_one_assignment(): void
+ {
+ // Regression test for issue #19809. The tile is meant to flag
+ // offboarding users who still hold items, so a leaver with
+ // nothing on record shouldn't inflate the count. Narrowing to
+ // users-with-assignments also matches the ?with_assignments=1
+ // filter the tile forwards to users.index.
+ //
+ // Formatted as Y-m-d because the User model's $rules enforce
+ // date_format:Y-m-d via Watson Validating. Passing a Carbon
+ // directly fails validation silently and never persists.
+ $withinWindow = now()->addDays(10)->format('Y-m-d');
+
+ // No assignments at all. Shouldn't register.
+ User::factory()->create(['end_date' => $withinWindow]);
+
+ // One asset assigned. Should register.
+ $leaverWithAsset = User::factory()->create(['end_date' => $withinWindow]);
+ Asset::factory()->create([
+ 'assigned_to' => $leaverWithAsset->id,
+ 'assigned_type' => User::class,
+ ]);
+
+ Livewire::withoutLazyLoading();
+ Livewire::actingAs(User::factory()->superuser()->create())
+ ->test(NeedsAttention::class)
+ ->assertSet('usersOffboardingSoon', 1);
+ }
+
+ public function test_users_offboarding_count_excludes_leavers_outside_window(): void
+ {
+ // Only end_dates within the 30-day window should count.
+ $assetOwner = User::factory()->create(['end_date' => now()->addDays(60)->format('Y-m-d')]);
+ Asset::factory()->create([
+ 'assigned_to' => $assetOwner->id,
+ 'assigned_type' => User::class,
+ ]);
+
+ Livewire::withoutLazyLoading();
+ Livewire::actingAs(User::factory()->superuser()->create())
+ ->test(NeedsAttention::class)
+ ->assertSet('usersOffboardingSoon', 0);
+ }
+
public function test_adheres_to_full_multiple_companies_support_scoping()
{
[$companyA, $companyB] = Company::factory()->count(2)->create();
diff --git a/tests/Feature/Users/Api/IndexUsersTest.php b/tests/Feature/Users/Api/IndexUsersTest.php
index c09154aec8..aff7dcda3d 100644
--- a/tests/Feature/Users/Api/IndexUsersTest.php
+++ b/tests/Feature/Users/Api/IndexUsersTest.php
@@ -202,4 +202,56 @@ class IndexUsersTest extends TestCase
])
->assertJson(fn (AssertableJson $json) => $json->has('rows', 0)->etc());
}
+
+ public function test_end_date_within_filters_to_users_leaving_in_window(): void
+ {
+ // Regression test for issue #19809. The dashboard's offboarding
+ // tile links to users.index?end_date_within=30, so the API has
+ // to narrow by range on end_date rather than equality.
+ $leavingSoon = User::factory()->create([
+ 'first_name' => 'Leaving',
+ 'end_date' => now()->addDays(10)->format('Y-m-d'),
+ ]);
+ User::factory()->create([
+ 'first_name' => 'Leaving Later',
+ 'end_date' => now()->addDays(60)->format('Y-m-d'),
+ ]);
+ User::factory()->create([
+ 'first_name' => 'Staying',
+ 'end_date' => null,
+ ]);
+
+ $response = $this->actingAsForApi(User::factory()->viewUsers()->create())
+ ->getJson(route('api.users.index', ['end_date_within' => 30]))
+ ->assertOk();
+
+ $response->assertJson(function (AssertableJson $json) use ($leavingSoon) {
+ $json->has('rows', 1)
+ ->where('rows.0.id', $leavingSoon->id)
+ ->etc();
+ });
+ }
+
+ public function test_with_assignments_filters_to_users_holding_at_least_one_item(): void
+ {
+ // Issue #19809. The offboarding tile narrows to users who are
+ // leaving AND still hold an assigned item, so the API filter
+ // backs the same cut.
+ $withAsset = User::factory()->create(['first_name' => 'Has Asset']);
+ Asset::factory()->create([
+ 'assigned_to' => $withAsset->id,
+ 'assigned_type' => User::class,
+ ]);
+ User::factory()->create(['first_name' => 'Has Nothing']);
+
+ $response = $this->actingAsForApi(User::factory()->viewUsers()->create())
+ ->getJson(route('api.users.index', ['with_assignments' => 1]))
+ ->assertOk();
+
+ $response->assertJson(function (AssertableJson $json) use ($withAsset) {
+ $json->has('rows', 1)
+ ->where('rows.0.id', $withAsset->id)
+ ->etc();
+ });
+ }
}