From: Lukas Reschke Date: Fri, 30 Jan 2015 11:00:57 +0000 (+0100) Subject: Fix subadmin listing of group X-Git-Tag: v8.0.0RC2~14^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=734dcc82dd48bc06a2152a45f9d62546e122b822;p=nextcloud-server.git Fix subadmin listing of group Without this patch filtering for the "_everyone" (empty) group did not work for subadmins. Fixes itself. --- diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php index be1b26f86ad..fd88692d777 100644 --- a/settings/controller/userscontroller.php +++ b/settings/controller/userscontroller.php @@ -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); } }