Merge pull request #13180 from nextcloud/backport/13171/stable14

[stable14] Use a case insensitive search for email
This commit is contained in:
Roeland Jago Douma 2018-12-20 20:38:02 +01:00 committed by GitHub
commit 1fc24cbcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View File

@ -459,6 +459,38 @@ class AllConfig implements \OCP\IConfig {
return $userIDs; return $userIDs;
} }
/**
* Determines the users that have the given value set for a specific app-key-pair
*
* @param string $appName the app to get the user for
* @param string $key the key to get the user for
* @param string $value the value to get the user for
* @return array of user IDs
*/
public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
// TODO - FIXME
$this->fixDIInit();
$sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
'WHERE `appid` = ? AND `configkey` = ? ';
if($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
//oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= 'AND LOWER(to_char(`configvalue`)) = LOWER(?)';
} else {
$sql .= 'AND LOWER(`configvalue`) = LOWER(?)';
}
$result = $this->connection->executeQuery($sql, array($appName, $key, $value));
$userIDs = array();
while ($row = $result->fetch()) {
$userIDs[] = $row['userid'];
}
return $userIDs;
}
public function getSystemConfig() { public function getSystemConfig() {
return $this->systemConfig; return $this->systemConfig;
} }

View File

@ -589,7 +589,7 @@ class Manager extends PublicEmitter implements IUserManager {
* @since 9.1.0 * @since 9.1.0
*/ */
public function getByEmail($email) { public function getByEmail($email) {
$userIds = $this->config->getUsersForUserValue('settings', 'email', $email); $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
$users = array_map(function($uid) { $users = array_map(function($uid) {
return $this->get($uid); return $this->get($uid);

View File

@ -8,6 +8,7 @@
*/ */
namespace Test\User; namespace Test\User;
use OC\AllConfig;
use OC\User\Database; use OC\User\Database;
use OC\User\Manager; use OC\User\Manager;
use OCP\IConfig; use OCP\IConfig;
@ -670,12 +671,12 @@ class ManagerTest extends TestCase {
} }
public function testGetByEmail() { public function testGetByEmail() {
$config = $this->getMockBuilder(IConfig::class) $config = $this->getMockBuilder(AllConfig::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$config $config
->expects($this->at(0)) ->expects($this->at(0))
->method('getUsersForUserValue') ->method('getUsersForUserValueCaseInsensitive')
->with('settings', 'email', 'test@example.com') ->with('settings', 'email', 'test@example.com')
->will($this->returnValue(['uid1', 'uid99', 'uid2'])); ->will($this->returnValue(['uid1', 'uid99', 'uid2']));