Optimierung 3.2: API-PR-Ownership-Scope + zentrale Eager-Loads
- PressRelease::scopeOwnedByApiUser() (bewusst eng: nur user_id-Autorschaft, anders als das breitere scopeAccessibleBy) ersetzt die byte-gleiche findOwnedPressRelease-Query in PressReleaseController + ImageController. - apiResourceRelations()-Helfer ersetzt den 5x identischen Eager-Load-Set (company/category.translations/images) in Index/Show/Create/Update/Reclassify. Bewusst NICHT umgesetzt: Slug-Reimplementierung (uniqueSlug) durch HasUniqueSlug ersetzen - der API-Fallback Str::random(8) weicht vom Trait-slugFallback() ab (Verhaltensaenderung bei leer-slugifizierten Titeln). Tests: neuer Scope-Test; volle Suite gruen (802 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
dba76910ca
commit
4fc46b02bf
4 changed files with 40 additions and 7 deletions
|
|
@ -22,6 +22,18 @@ test('accessibleBy includes a users own authored press release', function () {
|
|||
expect($ids)->toContain($pr->id);
|
||||
});
|
||||
|
||||
test('ownedByApiUser matches only the authoring user, not company access', function () {
|
||||
$author = User::factory()->create();
|
||||
$companyMate = User::factory()->create();
|
||||
$company = Company::factory()->create();
|
||||
$company->users()->attach($companyMate->id, ['role' => 'member']);
|
||||
|
||||
$pr = PressRelease::factory()->create(['user_id' => $author->id, 'company_id' => $company->id]);
|
||||
|
||||
expect(PressRelease::withoutGlobalScopes()->ownedByApiUser($author)->pluck('id'))->toContain($pr->id)
|
||||
->and(PressRelease::withoutGlobalScopes()->ownedByApiUser($companyMate)->pluck('id'))->not->toContain($pr->id);
|
||||
});
|
||||
|
||||
test('accessibleBy includes press releases of an assigned company', function () {
|
||||
$user = User::factory()->create();
|
||||
$company = Company::factory()->presseecho()->create();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue