From 6c8caa1641732c57fe59483fc2cdd5bcd7bd0163 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 25 Mar 2018 20:33:24 +0200 Subject: [PATCH 1/3] Remove deprecated \OCP\User::getUsers Signed-off-by: Roeland Jago Douma --- apps/user_ldap/tests/User_LDAPTest.php | 19 ++++++++++++++----- lib/private/Encryption/Util.php | 7 +++++-- lib/private/legacy/user.php | 19 ------------------- lib/public/User.php | 13 ------------- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 9911aa37e3..270e3eedbf 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -489,13 +489,22 @@ class User_LDAPTest extends TestCase { $this->assertEquals(0, count($result)); } + private function getUsers($search = '', $limit = null, $offset = null) { + $users = \OC::$server->getUserManager()->search($search, $limit, $offset); + $uids = []; + foreach ($users as $user) { + $uids[] = $user->getUID(); + } + return $uids; + } + public function testGetUsersViaAPINoParam() { $access = $this->getAccessMock(); $this->prepareAccessForGetUsers($access); $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::getUsers(); + $result = $this->getUsers(); $this->assertEquals(3, count($result)); } @@ -505,7 +514,7 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::getUsers('', 1, 2); + $result = $this->getUsers('', 1, 2); $this->assertEquals(1, count($result)); } @@ -515,7 +524,7 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::getUsers('', 2, 1); + $result = $this->getUsers('', 2, 1); $this->assertEquals(2, count($result)); } @@ -525,7 +534,7 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::getUsers('yo'); + $result = $this->getUsers('yo'); $this->assertEquals(2, count($result)); } @@ -535,7 +544,7 @@ class User_LDAPTest extends TestCase { $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); \OC_User::useBackend($backend); - $result = \OCP\User::getUsers('nix'); + $result = $this->getUsers('nix'); $this->assertEquals(0, count($result)); } diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index fc0adbbd47..1f5a511c39 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -271,9 +271,12 @@ class Util { } public function getUserWithAccessToMountPoint($users, $groups) { - $result = array(); + $result = []; if (in_array('all', $users)) { - $result = \OCP\User::getUsers(); + $users = $this->userManager->search('', null, null); + foreach ($users as $user) { + $result[] = $user->getUID(); + } } else { $result = array_merge($result, $users); diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php index 8f342281ad..07aa5a92f9 100644 --- a/lib/private/legacy/user.php +++ b/lib/private/legacy/user.php @@ -366,25 +366,6 @@ class OC_User { } } - /** - * Get a list of all users - * - * @return array an array of all uids - * - * Get a list of all users. - * @param string $search - * @param integer $limit - * @param integer $offset - */ - public static function getUsers($search = '', $limit = null, $offset = null) { - $users = \OC::$server->getUserManager()->search($search, $limit, $offset); - $uids = array(); - foreach ($users as $user) { - $uids[] = $user->getUID(); - } - return $uids; - } - /** * Get a list of all users display name * diff --git a/lib/public/User.php b/lib/public/User.php index 14fdd6fb1a..6e4e1d52a7 100644 --- a/lib/public/User.php +++ b/lib/public/User.php @@ -57,19 +57,6 @@ class User { return \OC_User::getUser(); } - /** - * Get a list of all users - * @param string $search search pattern - * @param int|null $limit - * @param int|null $offset - * @return array an array of all uids - * @deprecated 8.1.0 use method search() of \OCP\IUserManager - \OC::$server->getUserManager() - * @since 5.0.0 - */ - public static function getUsers( $search = '', $limit = null, $offset = null ) { - return \OC_User::getUsers( $search, $limit, $offset ); - } - /** * Get the user display name of the user currently logged in. * @param string|null $user user id or null for current user From 7ebd96416ca9150a4d524547a18b5fce269016ca Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 25 Mar 2018 20:42:03 +0200 Subject: [PATCH 2/3] Remove deprecated OCP\User::getDisplayname Signed-off-by: Roeland Jago Douma --- apps/files_sharing/lib/ShareBackend/Folder.php | 10 ++++++++-- apps/user_ldap/tests/User_LDAPTest.php | 4 ++-- lib/private/Share/Share.php | 6 ++++-- lib/private/legacy/user.php | 2 ++ lib/public/User.php | 12 ------------ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/apps/files_sharing/lib/ShareBackend/Folder.php b/apps/files_sharing/lib/ShareBackend/Folder.php index c48a26300a..0930f30eea 100644 --- a/apps/files_sharing/lib/ShareBackend/Folder.php +++ b/apps/files_sharing/lib/ShareBackend/Folder.php @@ -41,6 +41,9 @@ class Folder extends File implements \OCP\Share_Backend_Collection { public function getParents($itemSource, $shareWith = null, $owner = null) { $result = array(); $parent = $this->getParentId($itemSource); + + $userManager = \OC::$server->getUserManager(); + while ($parent) { $shares = \OCP\Share::getItemSharedWithUser('folder', $parent, $shareWith, $owner); if ($shares) { @@ -49,8 +52,11 @@ class Folder extends File implements \OCP\Share_Backend_Collection { $share['collection']['path'] = $name; $share['collection']['item_type'] = 'folder'; $share['file_path'] = $name; - $displayNameOwner = \OCP\User::getDisplayName($share['uid_owner']); - $displayNameShareWith = \OCP\User::getDisplayName($share['share_with']); + + $ownerUser = $userManager->get($share['uid_owner']); + $displayNameOwner = $ownerUser === null ? $share['uid_owner'] : $ownerUser->getDisplayName(); + $shareWithUser = $userManager->get($share['share_with']); + $displayNameShareWith = $shareWithUser === null ? $share['share_with'] : $shareWithUser->getDisplayName(); $share['displayname_owner'] = $displayNameOwner ? $displayNameOwner : $share['uid_owner']; $share['share_with_displayname'] = $displayNameShareWith ? $displayNameShareWith : $share['uid_owner']; diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 270e3eedbf..2b5952c974 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -1094,11 +1094,11 @@ class User_LDAPTest extends TestCase { ->willReturnCallback(function($uuid) { return $uuid . '1'; }); //with displayName - $result = \OCP\User::getDisplayName('gunslinger'); + $result = \OC::$server->getUserManager()->get('gunslinger')->getDisplayName(); $this->assertEquals('Roland Deschain', $result); //empty displayname retrieved - $result = \OCP\User::getDisplayName('newyorker'); + $result = \OC::$server->getUserManager()->get('newyorker')->getDisplayName(); $this->assertEquals('newyorker', $result); } diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 90a05ac51a..4211d6c8fc 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -1238,7 +1238,8 @@ class Share extends Constants { $row['share_with_displayname'] = $row['share_with']; if ( isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === self::SHARE_TYPE_USER) { - $row['share_with_displayname'] = \OCP\User::getDisplayName($row['share_with']); + $shareWithUser = \OC::$server->getUserManager()->get($row['share_with']); + $row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName(); } else if(isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === self::SHARE_TYPE_REMOTE) { $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']); @@ -1251,7 +1252,8 @@ class Share extends Constants { } } if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { - $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']); + $ownerUser = \OC::$server->get($row['uid_owner']); + $row['displayname_owner'] = $ownerUser === null ? $row['uid_owner'] : $ownerUser->getDisplayName(); } if ($row['permissions'] > 0) { diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php index 07aa5a92f9..9c877f22a4 100644 --- a/lib/private/legacy/user.php +++ b/lib/private/legacy/user.php @@ -312,6 +312,8 @@ class OC_User { * * @param string $uid * @return string|bool uid or false + * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method + * get() of \OCP\IUserManager - \OC::$server->getUserManager() */ public static function getDisplayName($uid = null) { if ($uid) { diff --git a/lib/public/User.php b/lib/public/User.php index 6e4e1d52a7..ba9039054b 100644 --- a/lib/public/User.php +++ b/lib/public/User.php @@ -57,18 +57,6 @@ class User { return \OC_User::getUser(); } - /** - * Get the user display name of the user currently logged in. - * @param string|null $user user id or null for current user - * @return string display name - * @deprecated 8.1.0 fetch \OCP\IUser (has getDisplayName()) by using method - * get() of \OCP\IUserManager - \OC::$server->getUserManager() - * @since 5.0.0 - */ - public static function getDisplayName( $user = null ) { - return \OC_User::getDisplayName( $user ); - } - /** * Check if the user is logged in * @return boolean From 74f0e3723327fbfb1cd7a96865019ff791b41593 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 25 Mar 2018 20:42:38 +0200 Subject: [PATCH 3/3] Remove deprecated \OCP\User::userExists Signed-off-by: Roeland Jago Douma --- apps/user_ldap/tests/User_LDAPTest.php | 9 ++++----- lib/private/Encryption/Util.php | 7 ++++--- lib/private/Share/Share.php | 2 +- lib/public/User.php | 12 ------------ 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 2b5952c974..5a165305d5 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -491,10 +491,9 @@ class User_LDAPTest extends TestCase { private function getUsers($search = '', $limit = null, $offset = null) { $users = \OC::$server->getUserManager()->search($search, $limit, $offset); - $uids = []; - foreach ($users as $user) { - $uids[] = $user->getUID(); - } + $uids = array_map(function(IUser $user) { + return $user->getUID(); + }, $users); return $uids; } @@ -1098,7 +1097,7 @@ class User_LDAPTest extends TestCase { $this->assertEquals('Roland Deschain', $result); //empty displayname retrieved - $result = \OC::$server->getUserManager()->get('newyorker')->getDisplayName(); + $result = \OC::$server->getUserManager()->get('newyorker') === null ? 'newyorker' : \OC::$server->getUserManager()->get('newyorker')->getDisplayName(); $this->assertEquals('newyorker', $result); } diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index 1f5a511c39..ddd19ac634 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -35,6 +35,7 @@ use OC\Files\Filesystem; use OC\Files\View; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; +use OCP\IUser; class Util { @@ -274,9 +275,9 @@ class Util { $result = []; if (in_array('all', $users)) { $users = $this->userManager->search('', null, null); - foreach ($users as $user) { - $result[] = $user->getUID(); - } + $result = array_map(function(IUser $user) { + return $user->getUID(); + }, $users); } else { $result = array_merge($result, $users); diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 4211d6c8fc..9c82fcc268 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -1252,7 +1252,7 @@ class Share extends Constants { } } if ( isset($row['uid_owner']) && $row['uid_owner'] != '') { - $ownerUser = \OC::$server->get($row['uid_owner']); + $ownerUser = \OC::$server->getUserManager()->get($row['uid_owner']); $row['displayname_owner'] = $ownerUser === null ? $row['uid_owner'] : $ownerUser->getDisplayName(); } diff --git a/lib/public/User.php b/lib/public/User.php index ba9039054b..a669a3a06f 100644 --- a/lib/public/User.php +++ b/lib/public/User.php @@ -67,18 +67,6 @@ class User { return \OC::$server->getUserSession()->isLoggedIn(); } - /** - * Check if a user exists - * @param string $uid the username - * @param string $excludingBackend (default none) - * @return boolean - * @deprecated 8.1.0 use method userExists() of \OCP\IUserManager - \OC::$server->getUserManager() - * @since 5.0.0 - */ - public static function userExists($uid, $excludingBackend = null) { - return \OC::$server->getUserManager()->userExists($uid); - } - /** * Check if the user is a admin, redirects to home if not * @since 5.0.0