Files
projectsend/app/Http/Middleware/RedirectToWhatsNew.php
T
ignacionelson 6ddfc1aa5d Greet the administrator once, on the first visit after an update
An update finished and nothing said so. The dashboard looked identical to
yesterday's, and whatever the release brought was in a file nobody opens.

The first time the installation's administrator opens ProjectSend after
an update, they now land on a page that names the version they are on,
invites them to the Discord — the same invitation update.sh prints, made
again where they are actually looking — and then lays out what the
release brought.

The notes come from CHANGELOG.md inside the release, not from GitHub: the
one moment this page exists for is the moment after an update, possibly
on a server with no outbound access, describing code already on disk.
Parsed rather than rendered, so nothing in it can become HTML.

Once, and to one person. The update happened to the installation, so
greeting five staff members — each having to dismiss a page they did not
ask for — would turn a pleasant moment into a support question. It goes
to the oldest active administrator, which on any installation that went
through setup is whoever set it up. No owner flag was invented for this:
administrators are equal in authority, and changing that for a greeting
is not a trade worth making.

Only forwards, and only for a real update. A fresh install has nothing to
catch up on, a container reboot has not updated anything, and somebody
restoring an older release is dealing with a problem rather than
celebrating. Managed installations never see it at all — nobody signed in
there performed the update it thanks them for, which is the same gate the
System card and About's environment block already carry.

The redirect is attached to the dashboard alone, not the web group: it
catches a login and the sidebar logo both, without ever interrupting a
download to congratulate somebody. Reading the page clears the marker,
but the address keeps working — closing it by accident should not be
unrecoverable — and About now links to it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 14:22:17 -03:00

44 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Modules\Platform\Updates\UpdateWelcome;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Takes the administrator to the welcome page the first time they arrive
* after an update.
*
* Attached to the dashboard alone rather than to the whole web group.
* The dashboard is where a login lands and where the sidebar's logo
* points, so it catches the arrival either way — including the common
* case on a self-hosted server, where the person who ran update.sh was
* already signed in and never logs in at all. Applying it to every
* request instead would mean intercepting somebody mid-download or
* mid-upload to congratulate them, which is a worse trade than missing
* an administrator who happens to bookmark /files.
*/
class RedirectToWhatsNew
{
public function __construct(private readonly UpdateWelcome $welcome) {}
public function handle(Request $request, Closure $next): Response
{
// GET only: a redirect swallows a POST body, and nothing that
// writes should ever be answered with a greeting.
if ($request->isMethod('GET')) {
$user = $request->user();
if ($user !== null && $this->welcome->isWaitingFor($user)) {
return redirect()->route('system.whats-new');
}
}
return $next($request);
}
}