diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-04-08 19:03:03 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-04-12 18:07:23 +0300 |
commit | 12e8767baa1074530af83cdb71b944608d01efa0 (patch) | |
tree | 60770abb1b8ded4fd307e0ecbfef5e4c9701d798 /lib/UserBackend.php | |
parent | e79ea7f6cb1c7ad97fd150425d53aabea52cc42d (diff) |
user search parity as with local users
* also take displayname and email into account
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/UserBackend.php')
-rw-r--r-- | lib/UserBackend.php | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/lib/UserBackend.php b/lib/UserBackend.php index bc8d9f3f..1b4f86af 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -264,27 +264,13 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function getUsers($search = '', $limit = null, $offset = null) { - /* @var $qb IQueryBuilder */ - $qb = $this->db->getQueryBuilder(); - $qb->select('uid', 'displayname') - ->from('user_saml_users') - ->where( - $qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) - ) - ->setMaxResults($limit); - if($offset !== null) { - $qb->setFirstResult($offset); - } - $result = $qb->execute(); - $users = $result->fetchAll(); - $result->closeCursor(); - - $uids = []; - foreach($users as $user) { - $uids[] = $user['uid']; - } - - return $uids; + // shamelessly duplicated from \OC\User\Database + $users = $this->getDisplayNames($search, $limit, $offset); + $userIds = array_map(function ($uid) { + return (string)$uid; + }, array_keys($users)); + sort($userIds, SORT_STRING | SORT_FLAG_CASE); + return $userIds; } /** @@ -356,29 +342,33 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function getDisplayNames($search = '', $limit = null, $offset = null) { - $qb = $this->db->getQueryBuilder(); - $qb->select('uid', 'displayname') - ->from('user_saml_users') - ->where( - $qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) - ) - ->orWhere( - $qb->expr()->iLike('displayname', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) + // shamelessly duplicate from \OC\User\Database + $query = $this->db->getQueryBuilder(); + + $query->select('uid', 'displayname') + ->from('user_saml_users', 'u') + ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( + $query->expr()->eq('userid', 'uid'), + $query->expr()->eq('appid', $query->expr()->literal('settings')), + $query->expr()->eq('configkey', $query->expr()->literal('email'))) ) - ->setMaxResults($limit); - if($offset !== null) { - $qb->setFirstResult($offset); + // sqlite doesn't like re-using a single named parameter here + ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orderBy($query->func()->lower('displayname'), 'ASC') + ->orderBy('uid', 'ASC') + ->setMaxResults($limit) + ->setFirstResult($offset); + + $result = $query->execute(); + $displayNames = []; + while ($row = $result->fetch()) { + $displayNames[(string)$row['uid']] = (string)$row['displayname']; } - $result = $qb->execute(); - $users = $result->fetchAll(); $result->closeCursor(); - $uids = []; - foreach($users as $user) { - $uids[$user['uid']] = $user['displayname']; - } - - return $uids; + return $displayNames; } /** |