diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2018-12-20 20:37:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 20:37:38 +0100 |
commit | 6eec2c06654ced9ddaf43a9e39354f06ebabc211 (patch) | |
tree | ad92a4e46225b5bc8a2b114634eb5fadf6b39fc0 | |
parent | e17a2bdfc76eabec55423a796b5714bd1c73ac7e (diff) | |
parent | 7b09d1192482093939027f45a633d5d0a12b7a38 (diff) | |
download | nextcloud-server-6eec2c06654ced9ddaf43a9e39354f06ebabc211.tar.gz nextcloud-server-6eec2c06654ced9ddaf43a9e39354f06ebabc211.zip |
Merge pull request #13179 from nextcloud/backport/13171/stable15
[stable15] Use a case insensitive search for email
-rw-r--r-- | lib/private/AllConfig.php | 32 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 2 | ||||
-rw-r--r-- | tests/lib/User/ManagerTest.php | 5 |
3 files changed, 36 insertions, 3 deletions
diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 58706e290fb..09520aae2a9 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -459,6 +459,38 @@ class AllConfig implements \OCP\IConfig { 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() { return $this->systemConfig; } diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 4243ced2e98..f1a2029a7d5 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -589,7 +589,7 @@ class Manager extends PublicEmitter implements IUserManager { * @since 9.1.0 */ public function getByEmail($email) { - $userIds = $this->config->getUsersForUserValue('settings', 'email', $email); + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); $users = array_map(function($uid) { return $this->get($uid); diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index e0b6aadf2ac..284f7b173bc 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -8,6 +8,7 @@ */ namespace Test\User; +use OC\AllConfig; use OC\User\Database; use OC\User\Manager; use OCP\IConfig; @@ -670,12 +671,12 @@ class ManagerTest extends TestCase { } public function testGetByEmail() { - $config = $this->getMockBuilder(IConfig::class) + $config = $this->getMockBuilder(AllConfig::class) ->disableOriginalConstructor() ->getMock(); $config ->expects($this->at(0)) - ->method('getUsersForUserValue') + ->method('getUsersForUserValueCaseInsensitive') ->with('settings', 'email', 'test@example.com') ->will($this->returnValue(['uid1', 'uid99', 'uid2'])); |