R1.1: Buchungs-Gate geprueft + safe-by-default; Legacy-Buchungspfade festgeschrieben
Default von billing.enforce_booking auf true gedreht: ein in Produktion vergessener Env-Key haette das Gate sonst still geoeffnet (jeder haette ohne Zahlung veroeffentlichen koennen). Tests ergaenzt: Grandfathered gueltig/abgelaufen/NULL (= abgelaufen, Entscheidung 19.06.), Active ausserhalb der Periode, Service-Level-Submit mit Legacy-Buchung und BookingRequiredException ohne Buchung. Scope-Logik selbst war korrekt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c3db80c651
commit
ad2879daa4
4 changed files with 109 additions and 9 deletions
10
.env.example
10
.env.example
|
|
@ -79,8 +79,8 @@ GOOGLE_CLIENT_ID=
|
|||
GOOGLE_CLIENT_SECRET=
|
||||
GOOGLE_REDIRECT_URI=https://pressekonto.com/auth/google/callback
|
||||
|
||||
# Abo-/Bestandsschutz-Gate (WS-5). Ist der Schalter aus, darf jeder einreichen
|
||||
# (Dev-Default). Für den Launch auf true setzen: Einreichen zur Prüfung erfordert
|
||||
# dann ein aktives Abo, einen bezahlten Einzelkauf oder Bestandsschutz
|
||||
# (grandfathered). Siehe User::hasActiveBooking().
|
||||
BILLING_ENFORCE_BOOKING=false
|
||||
# Abo-/Bestandsschutz-Gate (WS-5). Default (auch ohne Env-Key) ist true:
|
||||
# Einreichen zur Prüfung erfordert ein aktives Abo, einen bezahlten Einzelkauf
|
||||
# oder Bestandsschutz (grandfathered) — siehe User::hasActiveBooking().
|
||||
# Nur für lokale Entwicklung bewusst auf false setzen (Gate offen für alle).
|
||||
BILLING_ENFORCE_BOOKING=true
|
||||
|
|
|
|||
|
|
@ -8,13 +8,18 @@ return [
|
|||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| "Speichern" ist immer frei; "Speichern & zur Prüfung einreichen" ist
|
||||
| hinter eine aktive Buchung gegated. Bis das Tarif-Modul (Phase 9D/9E)
|
||||
| die echte Buchungs-Prüfung liefert, bleibt das Gate deaktiviert —
|
||||
| User::hasActiveBooking() gibt dann für alle true zurück.
|
||||
| hinter eine aktive Buchung gegated (Stripe-Abo, offener Einmalkauf oder
|
||||
| laufende Legacy-Vereinbarung inkl. Bestandsschutz).
|
||||
|
|
||||
| Default bewusst true (safe by default, R1.1 03.07.2026): Ein in
|
||||
| Produktion vergessener Env-Key darf das Gate nicht öffnen — sonst
|
||||
| könnte jeder ohne Zahlung veröffentlichen. Deaktivieren nur explizit
|
||||
| via BILLING_ENFORCE_BOOKING=false; dann gibt User::hasActiveBooking()
|
||||
| für alle true zurück.
|
||||
|
|
||||
*/
|
||||
|
||||
'enforce_booking' => env('BILLING_ENFORCE_BOOKING', false),
|
||||
'enforce_booking' => env('BILLING_ENFORCE_BOOKING', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -73,3 +73,62 @@ test('a cancelled legacy agreement does not count as booking', function () {
|
|||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('an active legacy agreement outside its current period does not count as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Active->value,
|
||||
'current_period_start' => now()->subMonths(2)->startOfMonth(),
|
||||
'current_period_end' => now()->subMonths(2)->endOfMonth(),
|
||||
'grandfathered_until' => null,
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement with valid protection counts as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => now()->addYear(),
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeTrue();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement with expired protection does not count as booking', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => now()->subDay(),
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
||||
test('a grandfathered agreement without an end date does not count as booking', function () {
|
||||
// NULL = abgelaufen/ungültig (User-Entscheidung 19.06.2026).
|
||||
$user = User::factory()->create();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'payment_option_id' => PaymentOption::factory()->create()->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => null,
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
expect($user->hasActiveBooking())->toBeFalse();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Enums\UserPaymentOptionStatus;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\SinglePurchase;
|
||||
use App\Models\User;
|
||||
use App\Models\UserPaymentOption;
|
||||
use App\Services\PressRelease\BookingRequiredException;
|
||||
use App\Services\PressRelease\PressReleaseService;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
|
@ -60,6 +66,36 @@ test('with the gate on a paid single purchase unlocks the submission action', fu
|
|||
->assertSee('Zur Prüfung einreichen');
|
||||
});
|
||||
|
||||
test('submitting without a booking is rejected at the service level', function () {
|
||||
/** @var TestCase $this */
|
||||
config()->set('billing.enforce_booking', true);
|
||||
Queue::fake();
|
||||
['pr' => $pr] = draftForGate();
|
||||
|
||||
expect(fn () => app(PressReleaseService::class)->submitForReview($pr))
|
||||
->toThrow(BookingRequiredException::class);
|
||||
|
||||
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Draft);
|
||||
});
|
||||
|
||||
test('a legacy grandfathered booking allows submitting for review', function () {
|
||||
/** @var TestCase $this */
|
||||
config()->set('billing.enforce_booking', true);
|
||||
Queue::fake();
|
||||
['customer' => $customer, 'pr' => $pr] = draftForGate();
|
||||
|
||||
UserPaymentOption::factory()->create([
|
||||
'user_id' => $customer->id,
|
||||
'status' => UserPaymentOptionStatus::Grandfathered->value,
|
||||
'grandfathered_until' => now()->addYear(),
|
||||
'stripe_subscription_id' => null,
|
||||
]);
|
||||
|
||||
app(PressReleaseService::class)->submitForReview($pr);
|
||||
|
||||
expect($pr->fresh()->status)->toBe(PressReleaseStatus::Review);
|
||||
});
|
||||
|
||||
test('with the gate off the notice never shows', function () {
|
||||
/** @var TestCase $this */
|
||||
config()->set('billing.enforce_booking', false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue