]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix subadmin listing of group
authorLukas Reschke <lukas@owncloud.com>
Fri, 30 Jan 2015 11:00:57 +0000 (12:00 +0100)
committerLukas Reschke <lukas@owncloud.com>
Fri, 30 Jan 2015 13:29:46 +0000 (14:29 +0100)
Without this patch filtering for the "_everyone" (empty) group did not work for subadmins.

Fixes itself.

settings/controller/userscontroller.php

index be1b26f86adafc8e176c379a30ed0738d5f2fb3f..fd88692d777355e5aec9597614383b18a8c14959 100644 (file)
@@ -161,7 +161,7 @@ class UsersController extends Controller {
        private function getUsersForUID(array $userIDs) {
                $users = [];
                foreach ($userIDs as $uid => $displayName) {
-                       $users[] = $this->userManager->get($uid);
+                       $users[$uid] = $this->userManager->get($uid);
                }
                return $users;
        }
@@ -196,7 +196,7 @@ class UsersController extends Controller {
                        }
                }
 
-               $users = array();
+               $users = [];
                if ($this->isAdmin) {
 
                        if($gid !== '') {
@@ -210,16 +210,31 @@ class UsersController extends Controller {
                        }
 
                } else {
+                       /** @var array $subAdminOf List of groups the user is subadmin */
+                       $subAdminOf = \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID());
+
                        // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
-                       if($gid !== '' && !in_array($gid, \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID()))) {
+                       if($gid !== '' && !in_array($gid, $subAdminOf)) {
                                $gid = '';
                        }
 
-                       $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
+                       // Batch all groups the user is subadmin of when a group is specified
+                       $batch = [];
+                       if($gid === '') {
+                               foreach($subAdminOf as $group) {
+                                       $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
+                                       foreach($groupUsers as $uid => $displayName) {
+                                               $batch[$uid] = $displayName;
+                                       }
+                               }
+                       } else {
+                               $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
+                       }
+                       $batch = $this->getUsersForUID($batch);
+
                        foreach ($batch as $user) {
                                // Only add the groups, this user is a subadmin of
-                               $userGroups = array_intersect($this->groupManager->getUserGroupIds($user),
-                                       \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID()));
+                               $userGroups = array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOf);
                                $users[] = $this->formatUserForIndex($user, $userGroups);
                        }
                }