Optimierung 3.1: Company::scopeAccessibleBy() zentralisiert Firmenzugriff
Die 4x identische Zugriffs-Closure (owner_user_id == me OR whereHas('users',
me)) in CompanyController (index/show), PressReleaseController::
findOwnedCompany und CustomerCompanyContext::accessibleCompanyQuery durch
einen Company::scopeAccessibleBy() ersetzt; das Scope-Verhalten
(withoutGlobalScopes) bleibt beim Aufrufer.
Bewusst unangetastet: User::accessibleCompanyIds() (relationenbasiert MIT
globalen Scopes - anderes Scope-Verhalten) und PressReleaseImageController
(prueft PR-Autorschaft user_id, nicht Firmenzugriff).
Tests: neuer Scope-Test; volle Suite gruen (801 passed, 1 skipped).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6a1240bdfb
commit
dba76910ca
5 changed files with 34 additions and 16 deletions
|
|
@ -144,10 +144,7 @@ class CustomerCompanyContext
|
|||
{
|
||||
return Company::query()
|
||||
->withoutGlobalScopes()
|
||||
->where(function ($query) use ($user): void {
|
||||
$query->where('owner_user_id', $user->id)
|
||||
->orWhereHas('users', fn ($userQuery) => $userQuery->whereKey($user->id));
|
||||
});
|
||||
->accessibleBy($user);
|
||||
}
|
||||
|
||||
public function findFor(User $user, int $companyId): ?Company
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue