Skip to content
Open
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
10 changes: 6 additions & 4 deletions app/Http/Controllers/StatusPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ public function showIndex()
} else {
$incidentDays = range(0, $daysToShow);
}
$windowSpan = $daysToShow + 1;
$oldestDateInWindow = $startDate->copy()->subDays($daysToShow);

$incidentVisibility = Auth::check() ? 0 : 1;

$allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->whereBetween('created_at', [
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00',
$oldestDateInWindow->format('Y-m-d').' 00:00:00',
$startDate->format('Y-m-d').' 23:59:59',
])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->load('updates')->groupBy(function (Incident $incident) {
return app(DateFactory::class)->make($incident->is_scheduled ? $incident->scheduled_at : $incident->created_at)->toDateString();
Expand All @@ -107,9 +109,9 @@ public function showIndex()
->withDaysToShow($daysToShow)
->withAllIncidents($allIncidents)
->withCanPageForward((bool) $today->gt($startDate))
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)
->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())
->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->count() > 0)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

withCanPageBackward(...) ignores the same visibility constraint used for $allIncidents (visible >= $incidentVisibility). For unauthenticated users this can surface a "previous" link even when only non-visible incidents exist before the current window, leading to navigation into empty/hidden pages. Consider reusing the same base query conditions (including visibility) and using ->exists() instead of ->count() > 0 to avoid a full COUNT scan.

Suggested change
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->count() > 0)
->withCanPageBackward(Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->where('created_at', '<', $oldestDateInWindow->format('Y-m-d').' 00:00:00')->exists())

Copilot uses AI. Check for mistakes.
->withPreviousDate($startDate->copy()->subDays($windowSpan)->toDateString())
->withNextDate($startDate->copy()->addDays($windowSpan)->toDateString());
}

/**
Expand Down
Loading