Adds search by email function on the users screen.
Fixes #7175. - Updated the query to fetch the users in users > everyone tab. - Updated the query to fetch the users in users > admin tab. - Tested to ensure that the disabled users are also being fetched. - Added test cases. Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
parent
bd1e357eef
commit
ec28c54dbc
|
@ -194,7 +194,10 @@ class Database extends Backend implements IUserBackend {
|
||||||
if ($search !== '') {
|
if ($search !== '') {
|
||||||
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
$searchLike = ' WHERE LOWER(`displayname`) LIKE LOWER(?) OR '
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
|
$searchLike .= ' LEFT JOIN `*PREFIX*preferences` ON `userid` = `uid` AND `appid` = \'settings\' AND `configkey` = \'email\'';
|
||||||
|
$searchLike .= ' WHERE LOWER(`configvalue`) LIKE LOWER(?)';
|
||||||
|
$searchLike .= ' OR LOWER(`displayname`) LIKE LOWER(?) OR '
|
||||||
. 'LOWER(`uid`) LIKE LOWER(?)';
|
. 'LOWER(`uid`) LIKE LOWER(?)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,8 +291,14 @@ class Database extends Backend implements IUserBackend {
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
$searchLike = '';
|
$searchLike = '';
|
||||||
if ($search !== '') {
|
if ($search !== '') {
|
||||||
|
// Email
|
||||||
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
$searchLike = ' WHERE LOWER(`uid`) LIKE LOWER(?)';
|
$searchLike .= ' LEFT JOIN `*PREFIX*preferences` ON `userid` = `uid` AND `appid` = \'settings\' AND `configkey` = \'email\'';
|
||||||
|
$searchLike .= ' WHERE LOWER(`configvalue`) LIKE LOWER(?)';
|
||||||
|
// UID
|
||||||
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
|
$searchLike .= ' OR LOWER(`uid`) LIKE LOWER(?)';
|
||||||
|
// Display name
|
||||||
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
$parameters[] = '%' . \OC::$server->getDatabaseConnection()->escapeLikeParameter($search) . '%';
|
||||||
$searchLike .= ' OR LOWER(`displayname`) LIKE LOWER(?)';
|
$searchLike .= ' OR LOWER(`displayname`) LIKE LOWER(?)';
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace Test\User;
|
||||||
use OC\HintException;
|
use OC\HintException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
use OC\User\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DatabaseTest
|
* Class DatabaseTest
|
||||||
|
@ -113,4 +114,28 @@ class DatabaseTest extends Backend {
|
||||||
$this->backend->createUser($user1, 'pw2');
|
$this->backend->createUser($user1, 'pw2');
|
||||||
$this->assertTrue($this->backend->userExists($user1));
|
$this->assertTrue($this->backend->userExists($user1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearch() {
|
||||||
|
parent::testSearch();
|
||||||
|
|
||||||
|
$user1 = $this->getUser();
|
||||||
|
$this->backend->createUser($user1, 'pass1');
|
||||||
|
|
||||||
|
$user2 = $this->getUser();
|
||||||
|
$this->backend->createUser($user2, 'pass1');
|
||||||
|
|
||||||
|
$user1Obj = new User($user1, $this->backend);
|
||||||
|
$user2Obj = new User($user2, $this->backend);
|
||||||
|
$emailAddr1 = "$user1@nextcloud.com";
|
||||||
|
$emailAddr2 = "$user2@nextcloud.com";
|
||||||
|
|
||||||
|
$user1Obj->setEMailAddress($emailAddr1);
|
||||||
|
$user2Obj->setEMailAddress($emailAddr2);
|
||||||
|
|
||||||
|
$result = $this->backend->getUsers('@nextcloud.com');
|
||||||
|
$this->assertSame(2, count($result));
|
||||||
|
|
||||||
|
$result = $this->backend->getDisplayNames('@nextcloud.com');
|
||||||
|
$this->assertSame(2, count($result));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue