Let a client account expire on a date

Staff can give a client an expiry date on the create and edit screens,
and through /api/v1/clients. When the date passes, the client is refused
at sign-in and on their next request, and their API access ends too.
Files and history stay, and a later date (or none) brings them back.

Access is checked through one predicate, User::maySignIn(), at every
door: sign-in, the web session, API tokens and the two-factor
challenge. An hourly sweep also switches `active` off, so the list,
its filter and seat counts agree. The sweep is not what enforces it,
so a scheduler that is not running cannot keep an account open.

An account cannot be active with a date that has passed. Reactivating
an expired client needs a new date in the same save.

The day-means-end-of-day-where-you-are rule moved out of FileExpiry
into a shared DateInput, so file and account expiry read dates the
same way.

Requested by @Drardollan in #1310.
This commit is contained in:
ignacionelson
2026-09-13 14:57:16 -03:00
parent 7c7ba7cd53
commit c21658f6f7
25 changed files with 761 additions and 51 deletions
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
// The instant a client account stops working. Null means it
// never does. See User::hasExpired() for how it is enforced,
// and ExpireClientAccountsCommand for why `active` is also
// switched off once it passes.
$table->timestamp('expires_at')->nullable()->after('erase_after')->index();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropIndex(['expires_at']);
$table->dropColumn('expires_at');
});
}
};