web/api/ki: Soft Deletes wieder wirksam, Caches bei Firmenwechsel, KI-Ergebnis an Inhalt gebunden (Audit Block 3+4, Deploy D)
Block 3 — Sichtbarkeit, Löschung, Cache, Eingaben F04: withoutGlobalScopes() ohne Argument entfernte neben dem PortalScope auch den Soft-Delete-Filter. Öffentliche, Kunden-, API-, Vorschau- und Medienpfade sowie die PressRelease-Helfer schreiben jetzt withoutGlobalScope(PortalScope::class). Zwei Stellen, die der Audit nicht kannte: die öffentliche Meldungsseite zeigte gelöschte Firmenkontakte mit Name, Mail und Telefon; das Pressefach listete gelöschte Kontakte weiter und ließ sie bearbeiten. Ein Architekturtest friert die 39 bewusst verbliebenen Stellen (Admin, Importer, Befehle, Slug-Eindeutigkeit) ein. Der Vorschau-Test prüfte bisher forceDelete statt delete. F22: LOWER(email) machte auf companies (110k Zeilen) bei jedem Login einen Vollscan; die Kollation ist ohnehin case-insensitiv. EmailQuery vergleicht auf MySQL direkt über den Index, auf SQLite (Tests) weiter per LOWER. Neuer Index contacts_email_idx. F13: Firmen-Observer verwirft die öffentlichen Seiten-Caches bei Löschung, Wiederherstellung und is_active-Wechsel auf jedem Weg; die Newsroom-Seite prüft Sichtbarkeit vor dem Cache-Treffer; Kontakt- Änderungen im Pressefach flushen. Der Tombstone-Test wärmte den Cache vorher nicht und traf den Fehler nie. F12: Gemeldete URLs werden über Host, Ausgabe und Slug aufgelöst (ReportedUrlResolver); fremde Hosts zählen nicht, bei Doppelveröffentlichung gewinnt die Erstquelle. F11: per_page 1–100, status als Enum, language nur de/en, Kategorie muss aktiv sein und zum Ziel-Portal passen. Legacy-Aliasse behalten ihren Vertrag. F23: Rückgabewert von put() wird geprüft; Logo erst speichern, dann Datenbank, dann altes Logo löschen. Fehler enden als Feldfehler, nicht als verlorenes Logo. Block 4 — KI-Prüfung und Scheduler F07: Klassifikation und Score tragen die Prüfsumme des Inhalts bei Einplanung. Weicht sie beim Speichern ab, wird das Ergebnis verworfen (ki_audits.discarded_at) und ein neuer Lauf eingeplant. Der Scheduler veröffentlicht keine Meldung, deren jüngste Klassifikation nicht zum aktuellen Text passt, sondern plant eine Prüfung mit Routing ein. F18: Kontingent an den Kalendermonat gebunden (users.press_release_quota_period). Verbrauch aus einem früheren Monat zählt null, auch ohne Reset-Cron; der Reset ist idempotent und lässt den laufenden Monat in Ruhe. F20: Der Publikations-Scheduler liefert bei technischen Fehlern einen Fehler-Exit-Code, damit der Failure-Hook greift. F17: KI-Jobs mit $timeout = 120, retry_after 150; Runbook ergänzt. F19: Aggregation der Aufrufe unter einem Cache-Lock für alle Einstiege. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
62202a4b13
commit
f235156de9
73 changed files with 1746 additions and 170 deletions
|
|
@ -1,11 +1,15 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Portal;
|
||||
use App\Models\Company;
|
||||
use App\Models\Contact;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\User;
|
||||
use App\Services\Customer\CustomerCompanyContext;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
|
@ -376,3 +380,105 @@ test('member customer cannot manage press kit company master data', function ()
|
|||
->call('startEditCompany')
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('a deleted press kit contact disappears from the list and cannot be edited (Audit F04)', function () {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
$company = Company::factory()->presseecho()->create(['owner_user_id' => $customer->id]);
|
||||
$contact = Contact::factory()->for($company)->create([
|
||||
'first_name' => 'Gelöschte',
|
||||
'last_name' => 'Kontaktperson',
|
||||
'portal' => $company->portal->value,
|
||||
]);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-kits.show', ['id' => $company->id])
|
||||
->assertSee('Kontaktperson')
|
||||
->call('deleteContact', $contact->id)
|
||||
->assertDontSee('Kontaktperson');
|
||||
|
||||
expect(fn () => LivewireVolt::test('customer.press-kits.show', ['id' => $company->id])
|
||||
->assertDontSee('Kontaktperson')
|
||||
->call('editContact', $contact->id))
|
||||
->toThrow(ModelNotFoundException::class);
|
||||
});
|
||||
|
||||
test('saving or deleting a press kit contact drops the cached newsroom page', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$company = Company::factory()->presseecho()->create(['is_active' => true]);
|
||||
$customer->companies()->attach($company->id, ['role' => 'responsible']);
|
||||
PressRelease::factory()
|
||||
->published()
|
||||
->forPortal(Portal::Presseecho)
|
||||
->for($company)
|
||||
->create(['language' => 'de', 'published_at' => now()->subDay()]);
|
||||
|
||||
$url = 'https://presseecho.test/de/newsroom/'.$company->slug;
|
||||
$cacheKey = fn (): string => webPageCacheKey('web.newsroom.presseecho-both.de.'.$company->slug.'.page.1');
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
// Aufwärmen — die Kontakte liegen mit im gecachten Seitenpaket.
|
||||
$this->get($url)->assertOk();
|
||||
expect(Cache::has($cacheKey()))->toBeTrue();
|
||||
|
||||
LivewireVolt::test('customer.press-kits.show', ['id' => $company->id])
|
||||
->call('startCreateContact')
|
||||
->set('contactLastName', 'Neu')
|
||||
->set('contactEmail', 'neu@example.test')
|
||||
->call('saveContact')
|
||||
->assertHasNoErrors();
|
||||
|
||||
// Der Key trägt die Generation: nach einem Flush existiert der alte
|
||||
// Eintrag unter dem neuen Key nicht mehr.
|
||||
expect(Cache::has($cacheKey()))->toBeFalse();
|
||||
|
||||
$contact = Contact::query()->where('company_id', $company->id)->firstOrFail();
|
||||
|
||||
$this->get($url)->assertOk();
|
||||
expect(Cache::has($cacheKey()))->toBeTrue();
|
||||
|
||||
LivewireVolt::test('customer.press-kits.show', ['id' => $company->id])
|
||||
->call('deleteContact', $contact->id);
|
||||
|
||||
expect(Cache::has($cacheKey()))->toBeFalse();
|
||||
});
|
||||
|
||||
test('a failed logo write keeps the previous press kit logo and reports a validation error', function () {
|
||||
/** @var TestCase $this */
|
||||
$disk = Storage::fake('public');
|
||||
$disk->put('company-logos/presseecho/7/alt.png', 'alt');
|
||||
$disk->put('company-logos/presseecho/7/alt-sq.png', 'alt-sq');
|
||||
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$company = Company::factory()->presseecho()->create([
|
||||
'logo_path' => 'company-logos/presseecho/7/alt.png',
|
||||
'logo_variants' => ['sq' => 'company-logos/presseecho/7/alt-sq.png'],
|
||||
]);
|
||||
$customer->companies()->attach($company->id, ['role' => 'responsible']);
|
||||
|
||||
// Proxy auf den echten Fake: nur put() schlägt fehl (voller Datenträger,
|
||||
// Rechteproblem), alles andere — auch Livewires Temp-Upload — läuft echt.
|
||||
$failingDisk = Mockery::mock($disk);
|
||||
$failingDisk->shouldReceive('put')->andReturn(false);
|
||||
Storage::set('public', $failingDisk);
|
||||
|
||||
$this->actingAs($customer);
|
||||
|
||||
LivewireVolt::test('customer.press-kits.show', ['id' => $company->id])
|
||||
->call('startEditCompany')
|
||||
->set('companyLogo', UploadedFile::fake()->image('neu.png', 400, 400))
|
||||
->call('saveCompany')
|
||||
->assertHasErrors(['companyLogo']);
|
||||
|
||||
$company->refresh();
|
||||
|
||||
expect($company->logo_path)->toBe('company-logos/presseecho/7/alt.png')
|
||||
->and($company->logo_variants)->toBe(['sq' => 'company-logos/presseecho/7/alt-sq.png'])
|
||||
->and($disk->exists('company-logos/presseecho/7/alt.png'))->toBeTrue()
|
||||
->and($disk->exists('company-logos/presseecho/7/alt-sq.png'))->toBeTrue();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue