mirror of
https://github.com/netzbegruenung/user_saml.git
synced 2024-05-04 10:03:42 +02:00
user search parity as with local users
* also take displayname and email into account Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
e79ea7f6cb
commit
12e8767baa
|
@ -264,27 +264,13 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
|
||||||
* @since 4.5.0
|
* @since 4.5.0
|
||||||
*/
|
*/
|
||||||
public function getUsers($search = '', $limit = null, $offset = null) {
|
public function getUsers($search = '', $limit = null, $offset = null) {
|
||||||
/* @var $qb IQueryBuilder */
|
// shamelessly duplicated from \OC\User\Database
|
||||||
$qb = $this->db->getQueryBuilder();
|
$users = $this->getDisplayNames($search, $limit, $offset);
|
||||||
$qb->select('uid', 'displayname')
|
$userIds = array_map(function ($uid) {
|
||||||
->from('user_saml_users')
|
return (string)$uid;
|
||||||
->where(
|
}, array_keys($users));
|
||||||
$qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%'))
|
sort($userIds, SORT_STRING | SORT_FLAG_CASE);
|
||||||
)
|
return $userIds;
|
||||||
->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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,29 +342,33 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
|
||||||
* @since 4.5.0
|
* @since 4.5.0
|
||||||
*/
|
*/
|
||||||
public function getDisplayNames($search = '', $limit = null, $offset = null) {
|
public function getDisplayNames($search = '', $limit = null, $offset = null) {
|
||||||
$qb = $this->db->getQueryBuilder();
|
// shamelessly duplicate from \OC\User\Database
|
||||||
$qb->select('uid', 'displayname')
|
$query = $this->db->getQueryBuilder();
|
||||||
->from('user_saml_users')
|
|
||||||
->where(
|
$query->select('uid', 'displayname')
|
||||||
$qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%'))
|
->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')))
|
||||||
)
|
)
|
||||||
->orWhere(
|
// sqlite doesn't like re-using a single named parameter here
|
||||||
$qb->expr()->iLike('displayname', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%'))
|
->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%')))
|
||||||
)
|
->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%')))
|
||||||
->setMaxResults($limit);
|
->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%')))
|
||||||
if($offset !== null) {
|
->orderBy($query->func()->lower('displayname'), 'ASC')
|
||||||
$qb->setFirstResult($offset);
|
->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();
|
$result->closeCursor();
|
||||||
|
|
||||||
$uids = [];
|
return $displayNames;
|
||||||
foreach($users as $user) {
|
|
||||||
$uids[$user['uid']] = $user['displayname'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $uids;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue