Skip to content

Commit e92f640

Browse files
committed
Api, return users details by groups
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 2465934 commit e92f640

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

apps/provisioning_api/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
// Users
4343
['root' => '/cloud', 'name' => 'Users#getUsers', 'url' => '/users', 'verb' => 'GET'],
4444
['root' => '/cloud', 'name' => 'Users#getUsersDetails', 'url' => '/users/details', 'verb' => 'GET'],
45+
['root' => '/cloud', 'name' => 'Users#getUsersGroupDetails', 'url' => '/users/{groupId}/details', 'verb' => 'GET'],
4546
['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'],
4647
['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'],
4748
['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,49 @@ public function getUsersDetails(string $search = '', $limit = null, $offset = 0)
193193
]);
194194
}
195195

196+
/**
197+
* @NoAdminRequired
198+
*
199+
* returns a list of users and their data based on their groupid
200+
*/
201+
public function getUsersGroupDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
202+
$user = $this->userSession->getUser();
203+
204+
$isSubadminOfGroup = false;
205+
$group = $this->groupManager->get($groupId);
206+
if ($group !== null) {
207+
$isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group);
208+
} else {
209+
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
210+
}
211+
212+
// Check subadmin has access to this group
213+
if($this->groupManager->isAdmin($user->getUID())
214+
|| $isSubadminOfGroup) {
215+
$users = $group->getUsers();
216+
$users = array_map(function($user) {
217+
/** @var IUser $user */
218+
return $user->getUID();
219+
}, $users);
220+
$users = array_slice(array_values($users), $offset, $limit);
221+
} else {
222+
throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
223+
}
224+
$usersDetails = [];
225+
foreach ($users as $key => $userId) {
226+
$userData = $this->getUserData($userId);
227+
// Do not insert empty entry
228+
if(!empty($userData)) {
229+
$usersDetails[$userId] = $userData;
230+
}
231+
}
232+
233+
return new DataResponse([
234+
'users' => $usersDetails
235+
]);
236+
237+
}
238+
196239
/**
197240
* @PasswordConfirmationRequired
198241
* @NoAdminRequired

0 commit comments

Comments
 (0)