diff options
Diffstat (limited to 'settings/controller/userscontroller.php')
-rw-r--r-- | settings/controller/userscontroller.php | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php index 1a77172db9b..8183bc4739b 100644 --- a/settings/controller/userscontroller.php +++ b/settings/controller/userscontroller.php @@ -74,8 +74,6 @@ class UsersController extends Controller { private $isEncryptionAppEnabled; /** @var bool contains the state of the admin recovery setting */ private $isRestoreEnabled = false; - /** @var SubAdminFactory */ - private $subAdminFactory; /** * @param string $appName @@ -92,7 +90,6 @@ class UsersController extends Controller { * @param string $fromMailAddress * @param IURLGenerator $urlGenerator * @param IAppManager $appManager - * @param SubAdminFactory $subAdminFactory */ public function __construct($appName, IRequest $request, @@ -107,8 +104,7 @@ class UsersController extends Controller { IMailer $mailer, $fromMailAddress, IURLGenerator $urlGenerator, - IAppManager $appManager, - SubAdminFactory $subAdminFactory) { + IAppManager $appManager) { parent::__construct($appName, $request); $this->userManager = $userManager; $this->groupManager = $groupManager; @@ -121,7 +117,6 @@ class UsersController extends Controller { $this->mailer = $mailer; $this->fromMailAddress = $fromMailAddress; $this->urlGenerator = $urlGenerator; - $this->subAdminFactory = $subAdminFactory; // check for encryption state - TODO see formatUserForIndex $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption'); @@ -164,11 +159,16 @@ class UsersController extends Controller { $restorePossible = true; } + $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); + foreach($subAdminGroups as $key => $subAdminGroup) { + $subAdminGroups[$key] = $subAdminGroup->getGID(); + } + return [ 'name' => $user->getUID(), 'displayname' => $user->getDisplayName(), 'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, - 'subadmin' => $this->subAdminFactory->getSubAdminsOfGroups($user->getUID()), + 'subadmin' => $subAdminGroups, 'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin() * 1000, @@ -234,9 +234,14 @@ class UsersController extends Controller { } } else { - $subAdminOfGroups = $this->subAdminFactory->getSubAdminsOfGroups( - $this->userSession->getUser()->getUID() - ); + $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser()); + // New class returns IGroup[] so convert back + $gids = []; + foreach ($subAdminOfGroups as $group) { + $gids[] = $group->getGID(); + } + $subAdminOfGroups = $gids; + // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group if($gid !== '' && !in_array($gid, $subAdminOfGroups)) { $gid = ''; @@ -247,6 +252,7 @@ class UsersController extends Controller { if($gid === '') { foreach($subAdminOfGroups as $group) { $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset); + foreach($groupUsers as $uid => $displayName) { $batch[$uid] = $displayName; } @@ -288,17 +294,31 @@ class UsersController extends Controller { ); } + $currentUser = $this->userSession->getUser(); + if (!$this->isAdmin) { - $userId = $this->userSession->getUser()->getUID(); if (!empty($groups)) { foreach ($groups as $key => $group) { - if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) { + $groupObject = $this->groupManager->get($group); + if($groupObject === null) { + unset($groups[$key]); + continue; + } + + if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) { unset($groups[$key]); } } } + if (empty($groups)) { - $groups = $this->subAdminFactory->getSubAdminsOfGroups($userId); + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($currentUser); + // New class returns IGroup[] so convert back + $gids = []; + foreach ($groups as $group) { + $gids[] = $group->getGID(); + } + $groups = $gids; } } @@ -391,6 +411,8 @@ class UsersController extends Controller { */ public function destroy($id) { $userId = $this->userSession->getUser()->getUID(); + $user = $this->userManager->get($id); + if($userId === $id) { return new DataResponse( array( @@ -403,7 +425,7 @@ class UsersController extends Controller { ); } - if(!$this->isAdmin && !$this->subAdminFactory->isUserAccessible($userId, $id)) { + if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { return new DataResponse( array( 'status' => 'error', @@ -415,7 +437,6 @@ class UsersController extends Controller { ); } - $user = $this->userManager->get($id); if($user) { if($user->delete()) { return new DataResponse( @@ -453,9 +474,11 @@ class UsersController extends Controller { */ public function setMailAddress($id, $mailAddress) { $userId = $this->userSession->getUser()->getUID(); + $user = $this->userManager->get($id); + if($userId !== $id && !$this->isAdmin - && !$this->subAdminFactory->isUserAccessible($userId, $id)) { + && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { return new DataResponse( array( 'status' => 'error', @@ -479,7 +502,6 @@ class UsersController extends Controller { ); } - $user = $this->userManager->get($id); if(!$user){ return new DataResponse( array( |