Skip to content

Commit

Permalink
Api, return users details by groups
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 23, 2018
1 parent 3d8fcad commit f428a0b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupUsers', 'url' => '/groups/{groupId}/users', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupUsersDetails', 'url' => '/groups/{groupId}/users/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'],
['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET'],
Expand Down
57 changes: 54 additions & 3 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,66 @@ public function getGroupsDetails(string $search = '', $limit = null, $offset = n
}

/**
* returns an array of users in the group specified
* @NoAdminRequired
*
* @param string $groupId
* @return DataResponse
* @throws OCSException
*
- * @deprecated 14 Use getGroupUsers
*/
public function getGroup(string $groupId): DataResponse {
return $this->getGroup(string $groupId);
}

/**
* returns an array of users in the specified group
*
* @NoAdminRequired
*
* @param string $groupId
* @return DataResponse
* @throws OCSException
*/
public function getGroup(string $groupId): DataResponse {
public function getGroupUsers(string $groupId): DataResponse {
$user = $this->userSession->getUser();

// Check the group exists
if(!$this->groupManager->groupExists($groupId)) {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
}

$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
}

// Check subadmin has access to this group
if($this->groupManager->isAdmin($user->getUID())
|| $isSubadminOfGroup) {
$users = $this->groupManager->get($groupId)->getUsers();
$users = array_map(function($user) {
/** @var IUser $user */
return $user->getUID();
}, $users);
$users = array_values($users);
return new DataResponse(['users' => $users]);
}

throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
}

/**
* returns an array of users details in the specified group
*
* @NoAdminRequired
*
* @param string $groupId
* @return DataResponse
* @throws OCSException
*/
public function getGroupUsersDetails(string $groupId): DataResponse {
$user = $this->userSession->getUser();

// Check the group exists
Expand All @@ -143,7 +194,7 @@ public function getGroup(string $groupId): DataResponse {
$isSubadminOfGroup = false;
$group = $this->groupManager->get($groupId);
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminofGroup($user, $group);
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
}

// Check subadmin has access to this group
Expand Down
4 changes: 2 additions & 2 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function addUser(string $userid, string $password = '', string $email='',
if(!$this->groupManager->groupExists($group)) {
throw new OCSException('group '.$group.' does not exist', 104);
}
if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) {
if(!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
throw new OCSException('insufficient privileges for group '. $group, 105);
}
}
Expand Down Expand Up @@ -808,7 +808,7 @@ public function addSubAdmin(string $userId, string $groupid): DataResponse {
$subAdminManager = $this->groupManager->getSubAdmin();

// We cannot be subadmin twice
if ($subAdminManager->isSubAdminofGroup($user, $group)) {
if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
return new DataResponse();
}
// Go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ public function testRemoveFromGroupAsSubAdminFromSubAdmin() {
->disableOriginalConstructor()->getMock();
$subAdminManager
->expects($this->once())
->method('isSubAdminofGroup')
->method('isSubAdminOfGroup')
->with($loggedInUser, $targetGroup)
->will($this->returnValue(true));
$this->groupManager
Expand Down Expand Up @@ -2445,7 +2445,7 @@ public function testRemoveFromGroupAsSubAdminFromLastSubAdminGroup() {
->disableOriginalConstructor()->getMock();
$subAdminManager
->expects($this->once())
->method('isSubAdminofGroup')
->method('isSubAdminOfGroup')
->with($loggedInUser, $targetGroup)
->will($this->returnValue(true));
$this->groupManager
Expand Down

0 comments on commit f428a0b

Please sign in to comment.