mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 00:55:07 +00:00
c21658f6f7
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.
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Files\Editing;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Files\Models\File;
|
|
use App\Modules\Platform\Localization\DateInput;
|
|
use Carbon\Carbon;
|
|
|
|
/**
|
|
* Reading and writing a file's expiry in the zone of whoever is looking.
|
|
*
|
|
* The rule itself — a posted day means the end of that day where the
|
|
* setter lives, and a form posts back what asShown() gave it — is
|
|
* DateInput's, shared with a client account's expiry. This stays as the
|
|
* file-shaped door onto it.
|
|
*
|
|
* Was three private copies — the staff editor, the API, and the client
|
|
* portal — of which the API's was the only one that could read a
|
|
* timestamp.
|
|
*/
|
|
class FileExpiry
|
|
{
|
|
public function __construct(
|
|
private readonly DateInput $dates,
|
|
) {}
|
|
|
|
/**
|
|
* The stored instant as the calendar day a form should show, in the
|
|
* viewer's zone. Null when the file never expires.
|
|
*/
|
|
public function asShown(File $file, ?User $viewer): ?string
|
|
{
|
|
return $this->dates->asShown($file->expires_at, $viewer);
|
|
}
|
|
|
|
/**
|
|
* The instant a submitted value actually names. See DateInput::instant().
|
|
*/
|
|
public function instant(?string $value, ?User $setter): ?Carbon
|
|
{
|
|
return $this->dates->instant($value, $setter);
|
|
}
|
|
}
|