diff options
Diffstat (limited to 'apps/provisioning_api/lib/users.php')
-rw-r--r-- | apps/provisioning_api/lib/users.php | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/provisioning_api/lib/users.php b/apps/provisioning_api/lib/users.php index fc5e79d4b2b..0b529bcea2c 100644 --- a/apps/provisioning_api/lib/users.php +++ b/apps/provisioning_api/lib/users.php @@ -29,6 +29,7 @@ namespace OCA\Provisioning_API; use \OC_OCS_Result; use \OC_SubAdmin; use \OC_Helper; +use \OC_Group; use OCP\Files\NotFoundException; class Users { @@ -71,7 +72,31 @@ class Users { $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; - $users = $this->userManager->search($search, $limit, $offset); + // Check if user is logged in + $user = $this->userSession->getUser(); + if ($user === null) { + return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); + } + + // Admin? Or SubAdmin? + if($this->groupManager->isAdmin($user->getUID())){ + $users = $this->userManager->search($search, $limit, $offset); + } else if (\OC_SubAdmin::isSubAdmin($user->getUID())) { + $subAdminOfGroups = \OC_SubAdmin::getSubAdminsGroups($user->getUID()); + + if($offset === null) { + $offset = 0; + } + + $users = []; + foreach ($subAdminOfGroups as $group) { + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); + } + + $users = array_slice($users, $offset, $limit); + } else { + return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); + } $users = array_keys($users); return new OC_OCS_Result([ |