Skip to content

Commit 6ca59f8

Browse files
committed
fix: join accounts_data instead of preferences when searching users
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 5cb16af commit 6ca59f8

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

lib/private/Group/Database.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,43 @@ public function searchInGroup(string $gid, string $search = '', int $limit = -1,
363363
$this->fixDI();
364364

365365
$query = $this->dbConn->getQueryBuilder();
366-
$query->select('g.uid', 'u.displayname');
366+
$query->select('g.uid', 'dn.value AS displayname', 'em.value AS email');
367367

368368
$query->from('group_user', 'g')
369369
->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
370370
->orderBy('g.uid', 'ASC');
371371

372-
$query->leftJoin('g', 'users', 'u', $query->expr()->eq('g.uid', 'u.uid'));
372+
// Join displayname and email from oc_accounts_data
373+
$query->leftJoin('g', 'accounts_data', 'dn',
374+
$query->expr()->andX(
375+
$query->expr()->eq('dn.uid', 'g.uid'),
376+
$query->expr()->eq('dn.name', $query->expr()->literal('displayname'))
377+
)
378+
);
379+
380+
$query->leftJoin('g', 'accounts_data', 'em',
381+
$query->expr()->andX(
382+
$query->expr()->eq('em.uid', 'g.uid'),
383+
$query->expr()->eq('em.name', $query->expr()->literal('email'))
384+
)
385+
);
373386

374387
if ($search !== '') {
375-
$query->leftJoin('u', 'preferences', 'p', $query->expr()->andX(
376-
$query->expr()->eq('p.userid', 'u.uid'),
377-
$query->expr()->eq('p.appid', $query->expr()->literal('settings')),
378-
$query->expr()->eq('p.configkey', $query->expr()->literal('email'))
379-
))
380-
// sqlite doesn't like re-using a single named parameter here
381-
->andWhere(
382-
$query->expr()->orX(
383-
$query->expr()->ilike('g.uid', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
384-
$query->expr()->ilike('u.displayname', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
385-
$query->expr()->ilike('p.configvalue', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))
386-
)
388+
// sqlite doesn't like re-using a single named parameter here
389+
$searchParam1 = $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%');
390+
$searchParam2 = $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%');
391+
$searchParam3 = $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%');
392+
393+
$query->andWhere(
394+
$query->expr()->orX(
395+
$query->expr()->ilike('g.uid', $searchParam1),
396+
$query->expr()->ilike('dn.value', $searchParam2),
397+
$query->expr()->ilike('em.value', $searchParam3)
387398
)
388-
->orderBy('u.uid_lower', 'ASC');
399+
);
389400
}
390401

402+
391403
if ($limit !== -1) {
392404
$query->setMaxResults($limit);
393405
}

0 commit comments

Comments
 (0)