Skip to content

Commit 9f92a01

Browse files
author
Ronald A Richardson
committed
refactor: remove redundant invite subquery from UserFilter
Now that User and CompanyUser are pinned to the production connection via getConnectionName(), the whereHas('companyUsers') check correctly finds all members regardless of sandbox mode. The orWhereExists invite subquery was a workaround for the wrong root cause and is no longer needed.
1 parent a7294ad commit 9f92a01

1 file changed

Lines changed: 4 additions & 21 deletions

File tree

src/Http/Filter/UserFilter.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,10 @@ public function queryForInternal()
88
{
99
$companyUuid = $this->session->get('company');
1010

11-
$this->builder->where(
12-
function ($query) use ($companyUuid) {
13-
// Include users who are already members of the company.
14-
$query->whereHas(
15-
'companyUsers',
16-
function ($q) use ($companyUuid) {
17-
$q->where('company_uuid', $companyUuid);
18-
}
19-
)
20-
// Also include users who have a pending invite to join the company
21-
// but have not yet accepted (no CompanyUser row exists yet).
22-
// The invites table has no user_uuid; the link is via the user's
23-
// email stored in the JSON recipients column.
24-
->orWhereExists(function ($q) use ($companyUuid) {
25-
$q->selectRaw(1)
26-
->from('invites')
27-
->whereRaw('JSON_CONTAINS(invites.recipients, JSON_QUOTE(users.email))')
28-
->where('invites.company_uuid', $companyUuid)
29-
->where('invites.reason', 'join_company')
30-
->whereNull('invites.deleted_at');
31-
});
11+
$this->builder->whereHas(
12+
'companyUsers',
13+
function ($q) use ($companyUuid) {
14+
$q->where('company_uuid', $companyUuid);
3215
}
3316
);
3417
}

0 commit comments

Comments
 (0)