diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-10-27 14:09:45 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-10-29 11:31:18 +0100 |
commit | c6f6a8758b3f08e47c3a8f45a67d09698376b2e2 (patch) | |
tree | bfd52190961e28ae97fa65a96df05b1fe0390a2f /settings/controller | |
parent | f428d31a5d1f91c6e7aa96fd8550c75c02cc0963 (diff) | |
download | nextcloud-server-c6f6a8758b3f08e47c3a8f45a67d09698376b2e2.tar.gz nextcloud-server-c6f6a8758b3f08e47c3a8f45a67d09698376b2e2.zip |
Drop OC_SubAdmin and replace usages
Diffstat (limited to 'settings/controller')
-rw-r--r-- | settings/controller/groupscontroller.php | 8 | ||||
-rw-r--r-- | settings/controller/userscontroller.php | 56 |
2 files changed, 45 insertions, 19 deletions
diff --git a/settings/controller/groupscontroller.php b/settings/controller/groupscontroller.php index 218a9c0d51c..93dcc7358a9 100644 --- a/settings/controller/groupscontroller.php +++ b/settings/controller/groupscontroller.php @@ -77,8 +77,12 @@ class GroupsController extends Controller { public function index($pattern = '', $filterGroups = false, $sortGroups = MetaData::SORT_USERCOUNT) { $groupPattern = $filterGroups ? $pattern : ''; - $groupsInfo = new MetaData($this->userSession->getUser()->getUID(), - $this->isAdmin, $this->groupManager); + $groupsInfo = new MetaData( + $this->userSession->getUser()->getUID(), + $this->isAdmin, + $this->groupManager, + $this->userSession + ); $groupsInfo->setSorting($sortGroups); list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern); 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( |