summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-03-20 19:06:08 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-04-05 17:08:59 +0200
commit68ae4394f712d884dc4814897cf97986f3cf71b3 (patch)
treeeff565001b846745c460e11a6c3c031a3ac01a77 /apps/provisioning_api
parent6ea444b24387e9b516a44000df0db0f6af786f95 (diff)
downloadnextcloud-server-68ae4394f712d884dc4814897cf97986f3cf71b3.tar.gz
nextcloud-server-68ae4394f712d884dc4814897cf97986f3cf71b3.zip
Api, return users details by groups
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/appinfo/routes.php2
-rw-r--r--apps/provisioning_api/lib/Controller/GroupsController.php66
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php6
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php4
4 files changed, 69 insertions, 9 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php
index c2bbd8025ee..5d1d2a6d501 100644
--- a/apps/provisioning_api/appinfo/routes.php
+++ b/apps/provisioning_api/appinfo/routes.php
@@ -36,6 +36,8 @@ return [
['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'],
diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php
index d6f2d9f3391..dc018fd94a9 100644
--- a/apps/provisioning_api/lib/Controller/GroupsController.php
+++ b/apps/provisioning_api/lib/Controller/GroupsController.php
@@ -36,6 +36,7 @@ use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\IUser;
+use OCA\Provisioning_API\Controller\UsersController;
class GroupsController extends OCSController {
@@ -49,24 +50,30 @@ class GroupsController extends OCSController {
/** @var ILogger */
private $logger;
+ /** @var UsersController */
+ private $userController;
+
/**
* @param string $appName
* @param IRequest $request
* @param IGroupManager $groupManager
* @param IUserSession $userSession
* @param ILogger $logger
+ * @param UsersController $userController
*/
public function __construct(
string $appName,
IRequest $request,
IGroupManager $groupManager,
IUserSession $userSession,
- ILogger $logger) {
+ ILogger $logger,
+ UsersController $userController) {
parent::__construct($appName, $request);
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->logger = $logger;
+ $this->userController = $userController;
}
/**
@@ -124,7 +131,20 @@ class GroupsController extends OCSController {
}
/**
- * 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($groupId);
+ }
+
+ /**
+ * returns an array of users in the specified group
*
* @NoAdminRequired
*
@@ -132,7 +152,7 @@ class GroupsController extends OCSController {
* @return DataResponse
* @throws OCSException
*/
- public function getGroup(string $groupId): DataResponse {
+ public function getGroupUsers(string $groupId): DataResponse {
$user = $this->userSession->getUser();
// Check the group exists
@@ -143,7 +163,7 @@ class GroupsController extends OCSController {
$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
@@ -162,6 +182,44 @@ class GroupsController extends OCSController {
}
/**
+ * 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
+ 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 $this->userController->getUserData($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);
+ }
+
+ /**
* creates a new group
*
* @PasswordConfirmationRequired
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index c8c00fa8592..4b452124295 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -225,7 +225,7 @@ class UsersController extends OCSController {
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);
}
}
@@ -341,7 +341,7 @@ class UsersController extends OCSController {
* @return array
* @throws OCSException
*/
- protected function getUserData(string $userId): array {
+ public function getUserData(string $userId): array {
$currentLoggedInUser = $this->userSession->getUser();
$data = [];
@@ -808,7 +808,7 @@ class UsersController extends OCSController {
$subAdminManager = $this->groupManager->getSubAdmin();
// We cannot be subadmin twice
- if ($subAdminManager->isSubAdminofGroup($user, $group)) {
+ if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
return new DataResponse();
}
// Go
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 3f2cf3b1105..0f53a7e6393 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -2394,7 +2394,7 @@ class UsersControllerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$subAdminManager
->expects($this->once())
- ->method('isSubAdminofGroup')
+ ->method('isSubAdminOfGroup')
->with($loggedInUser, $targetGroup)
->will($this->returnValue(true));
$this->groupManager
@@ -2445,7 +2445,7 @@ class UsersControllerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$subAdminManager
->expects($this->once())
- ->method('isSubAdminofGroup')
+ ->method('isSubAdminOfGroup')
->with($loggedInUser, $targetGroup)
->will($this->returnValue(true));
$this->groupManager