feat: API-Zugang endet mit der Buchung, optionales Ablaufdatum für API-Tokens
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run

Bisher blieb ein einmal erstellter Token gültig, auch wenn Abo bzw. Buchung
längst beendet waren. EnsureApiAccessIsBooked prüft jetzt bei jeder Anfrage
(v1 und /service/…-Altpfade), ob das Konto API-Zugang hat
(ApiAccessEligibilityService::hasApiAccess), sonst 403. Die Tokens bleiben
erhalten und funktionieren nach erneuter Buchung wieder.

Kunden können beim Erstellen optional ein Ablaufdatum setzen (bis 5 Jahre);
die Token-Liste zeigt „Gültig bis“ und einen Hinweis, wenn der Zugang
pausiert ist. sanctum:prune-expired räumt abgelaufene Tokens nach 30 Tagen
täglich ab. API-Doku (public/api/v1.yml) ergänzt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-10-08 11:41:24 +00:00
parent 7fa310fa76
commit 6d85d2982a
24 changed files with 319 additions and 66 deletions

View file

@ -1,14 +1,18 @@
<?php
use App\Enums\UserPaymentOptionStatus;
use App\Models\Category;
use App\Models\Company;
use App\Models\Contact;
use App\Models\PaymentOption;
use App\Models\Plan;
use App\Models\PressRelease;
use App\Models\User;
use App\Models\UserPaymentOption;
use App\Services\CurrentPortalContext;
use App\Support\WebPageCache;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
/*
@ -86,6 +90,34 @@ function subscribeUserToPlan(User $user, Plan $plan, string $interval = 'monthly
* `web.`-Seiten-Caches auf einmal. Die Tests prüfen weiterhin die fachliche
* Key-Struktur, nur eben generationsunabhängig.
*/
/**
* API-Zugang setzt eine laufende Buchung voraus (EnsureApiAccessIsBooked,
* 08.10.2026). Für API-Tests, die nicht die Buchung selbst prüfen: aktive
* Zahlungsoption anlegen.
*/
function grantApiAccess(User $user): User
{
UserPaymentOption::factory()->create([
'user_id' => $user->id,
'payment_option_id' => PaymentOption::factory()->create()->id,
'status' => UserPaymentOptionStatus::Active->value,
'current_period_start' => now()->subDay(),
'current_period_end' => now()->addMonth(),
]);
return $user;
}
/**
* Sanctum::actingAs() für einen Nutzer mit gebuchtem API-Zugang.
*
* @param list<string> $abilities
*/
function apiActingAs(User $user, array $abilities = ['*']): User
{
return Sanctum::actingAs(grantApiAccess($user), $abilities);
}
function webPageCacheKey(string $key): string
{
return 'web.g'.WebPageCache::generation().'.'.substr($key, strlen('web.'));