diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-01-30 14:16:16 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-01-30 14:29:46 +0100 |
commit | 7e7dd92f6b7c255ea7a94cbcf0e2e762ef49f8ee (patch) | |
tree | 6c13ea54580a5015f117d1b038b1120960e45479 /settings/controller | |
parent | 734dcc82dd48bc06a2152a45f9d62546e122b822 (diff) | |
download | nextcloud-server-7e7dd92f6b7c255ea7a94cbcf0e2e762ef49f8ee.tar.gz nextcloud-server-7e7dd92f6b7c255ea7a94cbcf0e2e762ef49f8ee.zip |
Add unit tests
Diffstat (limited to 'settings/controller')
-rw-r--r-- | settings/controller/userscontroller.php | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php index fd88692d777..39d94fd2e18 100644 --- a/settings/controller/userscontroller.php +++ b/settings/controller/userscontroller.php @@ -1,7 +1,7 @@ <?php /** * @author Lukas Reschke - * @copyright 2014 Lukas Reschke lukas@owncloud.com + * @copyright 2014-2015 Lukas Reschke lukas@owncloud.com * * This file is licensed under the Affero General Public License version 3 or * later. @@ -56,6 +56,8 @@ class UsersController extends Controller { private $isEncryptionAppEnabled; /** @var bool contains the state of the admin recovery setting */ private $isRestoreEnabled = false; + /** @var string[] Array of groups the user is sub-admin of */ + private $subAdminOfGroups = []; /** * @param string $appName @@ -70,7 +72,9 @@ class UsersController extends Controller { * @param \OC_Defaults $defaults * @param \OC_Mail $mail * @param string $fromMailAddress + * @param IURLGenerator $urlGenerator * @param IAppManager $appManager + * @param array $subAdminOfGroups */ public function __construct($appName, IRequest $request, @@ -85,7 +89,8 @@ class UsersController extends Controller { \OC_Mail $mail, $fromMailAddress, IURLGenerator $urlGenerator, - IAppManager $appManager) { + IAppManager $appManager, + array $subAdminOfGroups) { parent::__construct($appName, $request); $this->userManager = $userManager; $this->groupManager = $groupManager; @@ -98,6 +103,7 @@ class UsersController extends Controller { $this->mail = $mail; $this->fromMailAddress = $fromMailAddress; $this->urlGenerator = $urlGenerator; + $this->subAdminOfGroups = $subAdminOfGroups; // check for encryption state - TODO see formatUserForIndex $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('files_encryption'); @@ -210,18 +216,15 @@ 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, $subAdminOf)) { + if($gid !== '' && !in_array($gid, $this->subAdminOfGroups)) { $gid = ''; } // Batch all groups the user is subadmin of when a group is specified $batch = []; if($gid === '') { - foreach($subAdminOf as $group) { + foreach($this->subAdminOfGroups as $group) { $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); foreach($groupUsers as $uid => $displayName) { $batch[$uid] = $displayName; @@ -234,7 +237,10 @@ class UsersController extends Controller { foreach ($batch as $user) { // Only add the groups, this user is a subadmin of - $userGroups = array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOf); + $userGroups = array_values(array_intersect( + $this->groupManager->getUserGroupIds($user), + $this->subAdminOfGroups + )); $users[] = $this->formatUserForIndex($user, $userGroups); } } @@ -274,7 +280,7 @@ class UsersController extends Controller { } } if (empty($groups)) { - $groups = \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID()); + $groups = $this->subAdminOfGroups; } } |