]> source.dussan.org Git - nextcloud-server.git/commitdiff
Clear up return types
authorCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 2 Jan 2023 16:10:31 +0000 (17:10 +0100)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 27 Apr 2023 10:00:45 +0000 (12:00 +0200)
usersInGroup index by int for BC, searchInGroup index by uid (string).

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
apps/user_ldap/lib/Access.php
apps/user_ldap/lib/Group_LDAP.php
apps/user_ldap/lib/Group_Proxy.php
lib/private/Group/Backend.php
lib/private/Group/Database.php
lib/private/Group/Group.php
lib/public/Group/Backend/ISearchableGroupBackend.php
lib/public/GroupInterface.php
tests/lib/Group/ManagerTest.php
tests/lib/Util/Group/Dummy.php

index 9a97a28c376cc6e7e67efd77dbdfeaeff893faaf..3f120caefe6f1ae64dd50e7c75cc4e67bdb15453 100644 (file)
@@ -631,7 +631,7 @@ class Access extends LDAPUtility {
         * gives back the user names as they are used ownClod internally
         *
         * @param array $ldapUsers as returned by fetchList()
-        * @return array an array with the user names to use in Nextcloud
+        * @return array<int,string> an array with the user names to use in Nextcloud
         *
         * gives back the user names as they are used ownClod internally
         * @throws \Exception
@@ -644,7 +644,7 @@ class Access extends LDAPUtility {
         * gives back the group names as they are used ownClod internally
         *
         * @param array $ldapGroups as returned by fetchList()
-        * @return array an array with the group names to use in Nextcloud
+        * @return array<int,string> an array with the group names to use in Nextcloud
         *
         * gives back the group names as they are used ownClod internally
         * @throws \Exception
@@ -655,6 +655,7 @@ class Access extends LDAPUtility {
 
        /**
         * @param array[] $ldapObjects as returned by fetchList()
+        * @return array<int,string>
         * @throws \Exception
         */
        private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array {
index fac71093665318444573ae9fed41473c0053df33..84267171d3749fba4a964cd6b96060575db3c9c5 100644 (file)
@@ -466,7 +466,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
        }
 
        /**
-        * @return array A list of users that have the given group as gid number
+        * @return array<int,string> A list of users that have the given group as gid number
         * @throws ServerNotAvailableException
         */
        public function getUsersInGidNumber(
@@ -591,6 +591,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
 
        /**
         * @throws ServerNotAvailableException
+        * @return array<int,string>
         */
        public function getUsersInPrimaryGroup(
                string $groupDN,
@@ -840,7 +841,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
         * @param string $search
         * @param int $limit
         * @param int $offset
-        * @return array with user ids
+        * @return array<int,string> user ids
         * @throws Exception
         * @throws ServerNotAvailableException
         */
@@ -909,7 +910,11 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
                                        if (empty($ldap_users)) {
                                                break;
                                        }
-                                       $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
+                                       $uid = $this->access->dn2username($ldap_users[0]['dn'][0]);
+                                       if (!$uid) {
+                                               break;
+                                       }
+                                       $groupUsers[] = $uid;
                                        break;
                                default:
                                        //we got DNs, check if we need to filter by search or we can give back all of them
index 74655840f479cf7cd35e6c7c0fd6f4865c736a16..5f8d0562fd91853d214c5fd96581c7e0fdd1ea5b 100644 (file)
@@ -171,7 +171,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
        /**
         * get a list of all users in a group
         *
-        * @return string[] with user ids
+        * @return array<int,string> user ids
         */
        public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
                $this->setup();
index 037cdacf4453e2ffd9d2474b61a86cd413909509..1e3e5ef1164a31a2634f08ff102472e3b04d68b2 100644 (file)
@@ -126,7 +126,7 @@ abstract class Backend implements \OCP\GroupInterface {
         * @param string $search
         * @param int $limit
         * @param int $offset
-        * @return array an array of user ids
+        * @return array<int,string> an array of user ids
         */
        public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
                return [];
index 13e4906c29852ee01beb070e1f278ea49ae0e37c..569cfa5007f345cf6595889fd9609abf724b2866 100644 (file)
@@ -333,10 +333,10 @@ class Database extends ABackend implements
         * @param string $search
         * @param int $limit
         * @param int $offset
-        * @return array<string> an array of user ids
+        * @return array<int,string> an array of user ids
         */
        public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array {
-               return array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset));
+               return array_values(array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset)));
        }
 
        public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {
index f70221de8bd4dc3417254f26be5990649643c16c..c72a7826fd04d4bb5b7f9565b82b848b7328a023 100644 (file)
@@ -251,7 +251,7 @@ class Group implements IGroup {
                $users = [];
                foreach ($this->backends as $backend) {
                        if ($backend instanceof ISearchableGroupBackend) {
-                               $users = array_merge($users, $backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0));
+                               $users = array_merge($users, array_values($backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0)));
                        } else {
                                $userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
                                $userManager = \OCP\Server::get(IUserManager::class);
index 4e03680f75a9803cf9375ef51e58a2322989d711..e5861d2814c2e87aaf47bf110dfc338e878aafd5 100644 (file)
@@ -29,7 +29,6 @@ use OCP\IUser;
  * @since 26.0.0
  */
 interface ISearchableGroupBackend {
-
        /**
         * @brief Get a list of users matching the given search parameters.
         *
@@ -45,7 +44,7 @@ interface ISearchableGroupBackend {
         *                       want to search. This can be empty to get all the users.
         * @param int $limit     The limit of results
         * @param int $offset    The offset of the results
-        * @return IUser[]
+        * @return array<string,IUser> Users indexed by uid
         * @since 26.0.0
         */
        public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array;
index 7a3c396054170cc035e6829f58412503e8360970..726921920af0041c314c26143be5a37686d4ea2e 100644 (file)
@@ -112,7 +112,7 @@ interface GroupInterface {
         * @param string $search
         * @param int $limit
         * @param int $offset
-        * @return array an array of user ids
+        * @return array<int,string> an array of user ids
         * @since 4.5.0
         * @deprecated 26.0.0 Use searchInGroup instead, for performance reasons
         */
index 1bdb221934685bcaa22ba2b77c7875f827b12ed6..186f9d619a29afca87d2a788a333b7478a6f9fb2 100644 (file)
@@ -737,7 +737,7 @@ class ManagerTest extends TestCase {
                $backend->expects($this->once())
                        ->method('searchInGroup')
                        ->with('testgroup', '', -1, 0)
-                       ->willReturn([$this->getTestUser('user2'), $this->getTestUser('user33')]);
+                       ->willReturn(['user2' => $this->getTestUser('user2'), 'user33' => $this->getTestUser('user33')]);
 
                $this->userManager->expects($this->never())->method('get');
 
@@ -793,7 +793,7 @@ class ManagerTest extends TestCase {
                $backend->expects($this->once())
                        ->method('searchInGroup')
                        ->with('testgroup', '', 1, 1)
-                       ->willReturn([$this->getTestUser('user33')]);
+                       ->willReturn(['user33' => $this->getTestUser('user33')]);
 
                $this->userManager->expects($this->never())->method('get');
 
index 2d86e45cfc1646491d4192ad0c7a6fc18899635f..a864c8ce9d992eaad940dc643b093a52e97af697 100644 (file)
@@ -208,7 +208,7 @@ class Dummy extends ABackend implements ICreateGroupBackend, IDeleteGroupBackend
                        $result = [];
                        foreach ($this->groups[$gid] as $user) {
                                if (stripos($user, $search) !== false) {
-                                       $result[] = new DummyUser($user, '');
+                                       $result[$user] = new DummyUser($user, '');
                                }
                        }
                        return $result;