diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-03-16 09:18:53 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-03-16 09:19:47 +0100 |
commit | ce625bbad52bd7d416d5fdaac6bef399feaf0c3b (patch) | |
tree | d26e8008a5750e3deb4565ebed8d40193dbaec1f /apps/provisioning_api | |
parent | fa886ef4eba0d7bdfdccc5e46de9971174598394 (diff) | |
download | nextcloud-server-ce625bbad52bd7d416d5fdaac6bef399feaf0c3b.tar.gz nextcloud-server-ce625bbad52bd7d416d5fdaac6bef399feaf0c3b.zip |
Add userdetails to ocs api
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r-- | apps/provisioning_api/appinfo/routes.php | 1 | ||||
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 73 |
2 files changed, 71 insertions, 3 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php index aa5a30199a7..791267a97a1 100644 --- a/apps/provisioning_api/appinfo/routes.php +++ b/apps/provisioning_api/appinfo/routes.php @@ -41,6 +41,7 @@ return [ // Users ['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'], + ['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'], ['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'], ['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'], diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 087e65a1bca..17c04c708f1 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -159,6 +159,55 @@ class UsersController extends OCSController { } /** + * @NoAdminRequired + * + * returns a list of users and their data + * + * @param string $search + * @param int $offset + * @return DataResponse + */ + public function getUsersDetails(string $search = '', $offset = null): DataResponse { + // Limit set to 25 for performance issues + $limit = 25; + $user = $this->userSession->getUser(); + $users = []; + + // Admin? Or SubAdmin? + $uid = $user->getUID(); + $subAdminManager = $this->groupManager->getSubAdmin(); + if($this->groupManager->isAdmin($uid)){ + $users = $this->userManager->search($search, $limit, $offset); + } else if ($subAdminManager->isSubAdmin($user)) { + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); + foreach ($subAdminOfGroups as $key => $group) { + $subAdminOfGroups[$key] = $group->getGID(); + } + + 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); + } + + $users = array_keys($users); + $usersDetails = []; + foreach ($users as $key => $userId) { + $usersDetails[$userId] = $this->getUserData($userId); + } + + return new DataResponse([ + 'users' => $usersDetails + ]); + } + + /** * @PasswordConfirmationRequired * @NoAdminRequired * @@ -281,6 +330,10 @@ class UsersController extends OCSController { if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); + $data['storageLocation'] = $targetUserObject->getHome(); + $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; + $data['backend'] = $targetUserObject->getBackendClassName(); + $data['subadmins'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); } else { // Check they are looking up themselves if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { @@ -288,6 +341,7 @@ class UsersController extends OCSController { } } + // Get groups data $userAccount = $this->accountManager->getUser($targetUserObject); $groups = $this->groupManager->getUserGroups($targetUserObject); $gids = []; @@ -779,10 +833,10 @@ class UsersController extends OCSController { * Get the groups a user is a subadmin of * * @param string $userId - * @return DataResponse + * @return array * @throws OCSException */ - public function getUserSubAdminGroups(string $userId): DataResponse { + protected function getUserSubAdminGroupsData(string $userId): array { $user = $this->userManager->get($userId); // Check if the user exists if($user === null) { @@ -796,10 +850,23 @@ class UsersController extends OCSController { $groups[] = $group->getGID(); } + return $groups; + } + + /** + * Get the groups a user is a subadmin of + * + * @param string $userId + * @return DataResponse + * @throws OCSException + */ + public function getUserSubAdminGroups(string $userId): DataResponse { + $groups = $this->getUserSubAdminGroupsData($userId); + if(!$groups) { throw new OCSException('Unknown error occurred', 102); } else { - return new DataResponse($groups); + return $groups; } } |