fix(auth): offer every clinic a user owns as a switchable context
buildAvailableContexts used ClinicRepository::findByUser(), which is a findOneBy — so a user who owns two clinics only ever saw the first one. switchContext validates its input against that same list, so the second clinic could not be selected at all. Before tenant isolation this was merely annoying. Since phase 4 it is a blocker: an environment that cannot be selected is an environment TenantFilter hides from its own owner. Found by running the suite against an imported production database, where one account owns two clinics and its second clinic had become unreachable. findByUser() stays for the fallbacks that only need "some clinic"; the context list now uses findAllByUser(). The other 20 findByUser() call sites are single-clinic fallbacks used when no context is chosen, and keep their current behaviour — once the owner can switch, UserActiveContext decides. Removing the fix turns 3 of the 4 new tests red. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -734,8 +734,10 @@ class AuthController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
// صاحب کلینیک (اگر قبلاً اضافه نشده)
|
||||
if ($clinic = $this->clinicRepo->findByUser($user)) {
|
||||
// صاحب کلینیک — **همهٔ** کلینیکهایش، نه فقط اولی: با جداسازی محیط، محیطی که
|
||||
// در این فهرست نباشد قابل انتخاب نیست و دادهٔ همان کلینیک برای مالکش هم
|
||||
// نامرئی میماند.
|
||||
foreach ($this->clinicRepo->findAllByUser($user) as $clinic) {
|
||||
$alreadyAdded = array_filter($contexts, fn($c) => $c['db_uuid'] === $clinic->getUuid());
|
||||
if (empty($alreadyAdded)) {
|
||||
$contexts[] = [
|
||||
|
||||
Reference in New Issue
Block a user