Skip to content

Commit 0d4320c

Browse files
author
Ronald A Richardson
committed
fix: include pending-invite users in IAM user list
The UserFilter::queryForInternal() was scoped exclusively to users with a CompanyUser row for the current company. Newly invited users have no CompanyUser record until they accept their invite, so they were invisible in the IAM list. The fix adds an orWhereExists() subquery that also matches users whose email address appears in the recipients JSON column of a non-deleted join_company invite for the current company. This covers both the brand-new pending user path and the cross-org invite path. JSON_CONTAINS(invites.recipients, JSON_QUOTE(users.email)) is used instead of whereHas() because the invites table has no user_uuid column; the user is identified solely by their email in the recipients array.
1 parent 1363cd4 commit 0d4320c

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

src/Http/Filter/UserFilter.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ class UserFilter extends Filter
66
{
77
public function queryForInternal()
88
{
9+
$companyUuid = $this->session->get('company');
10+
911
$this->builder->where(
10-
function ($query) {
11-
$query
12-
->whereHas(
13-
'companyUsers',
14-
function ($query) {
15-
$query->where('company_uuid', $this->session->get('company'));
16-
}
17-
);
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+
});
1832
}
1933
);
2034
}

0 commit comments

Comments
 (0)