aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib/Controller/GroupsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/lib/Controller/GroupsController.php')
-rw-r--r--apps/provisioning_api/lib/Controller/GroupsController.php135
1 files changed, 92 insertions, 43 deletions
diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php
index d6f2d9f3391..c2958bc4778 100644
--- a/apps/provisioning_api/lib/Controller/GroupsController.php
+++ b/apps/provisioning_api/lib/Controller/GroupsController.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Tom Needham <tom@owncloud.com>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0
*
@@ -27,24 +28,21 @@ declare(strict_types=1);
namespace OCA\Provisioning_API\Controller;
+use OC\Accounts\AccountManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
-use OCP\AppFramework\OCSController;
+use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\AppFramework\OCS\OCSForbiddenException;
+use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IRequest;
+use OCP\IUserManager;
use OCP\IUserSession;
use OCP\IUser;
-
-class GroupsController extends OCSController {
-
- /** @var IGroupManager */
- private $groupManager;
-
- /** @var IUserSession */
- private $userSession;
+class GroupsController extends AUserData {
/** @var ILogger */
private $logger;
@@ -52,20 +50,30 @@ class GroupsController extends OCSController {
/**
* @param string $appName
* @param IRequest $request
+ * @param IUserManager $userManager
+ * @param IConfig $config
* @param IGroupManager $groupManager
* @param IUserSession $userSession
+ * @param AccountManager $accountManager
* @param ILogger $logger
+ * @param UsersController $userController
*/
- public function __construct(
- string $appName,
- IRequest $request,
- IGroupManager $groupManager,
- IUserSession $userSession,
- ILogger $logger) {
- parent::__construct($appName, $request);
-
- $this->groupManager = $groupManager;
- $this->userSession = $userSession;
+ public function __construct(string $appName,
+ IRequest $request,
+ IUserManager $userManager,
+ IConfig $config,
+ IGroupManager $groupManager,
+ IUserSession $userSession,
+ AccountManager $accountManager,
+ ILogger $logger) {
+ parent::__construct($appName,
+ $request,
+ $userManager,
+ $config,
+ $groupManager,
+ $userSession,
+ $accountManager);
+
$this->logger = $logger;
}
@@ -79,14 +87,7 @@ class GroupsController extends OCSController {
* @param int $offset
* @return DataResponse
*/
- public function getGroups(string $search = '', $limit = null, $offset = null): DataResponse {
- if ($limit !== null) {
- $limit = (int)$limit;
- }
- if ($offset !== null) {
- $offset = (int)$offset;
- }
-
+ public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
@@ -106,14 +107,7 @@ class GroupsController extends OCSController {
* @param int $offset
* @return DataResponse
*/
- public function getGroupsDetails(string $search = '', $limit = null, $offset = null): DataResponse {
- if ($limit !== null) {
- $limit = (int)$limit;
- }
- if ($offset !== null) {
- $offset = (int)$offset;
- }
-
+ public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
@@ -124,7 +118,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->getGroupUsers($groupId);
+ }
+
+ /**
+ * returns an array of users in the specified group
*
* @NoAdminRequired
*
@@ -132,18 +139,16 @@ class GroupsController extends OCSController {
* @return DataResponse
* @throws OCSException
*/
- public function getGroup(string $groupId): DataResponse {
+ public function getGroupUsers(string $groupId): DataResponse {
$user = $this->userSession->getUser();
+ $isSubadminOfGroup = false;
// 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);
+ $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
+ } else {
+ throw new OCSNotFoundException('The requested group could not be found');
}
// Check subadmin has access to this group
@@ -158,6 +163,50 @@ class GroupsController extends OCSController {
return new DataResponse(['users' => $users]);
}
+ throw new OCSForbiddenException();
+ }
+
+ /**
+ * returns an array of users details in the specified group
+ *
+ * @NoAdminRequired
+ *
+ * @param string $groupId
+ * @param int $limit
+ * @param int $offset
+ * @return DataResponse
+ * @throws OCSException
+ */
+ public function getGroupUsersDetails(string $groupId, int $limit = null, int $offset = 0): DataResponse {
+ $user = $this->userSession->getUser();
+ $isSubadminOfGroup = false;
+
+ // Check the group exists
+ $group = $this->groupManager->get($groupId);
+ if ($group !== null) {
+ $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
+ } else {
+ throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
+ }
+
+ // Check subadmin has access to this group
+ if($this->groupManager->isAdmin($user->getUID())
+ || $isSubadminOfGroup) {
+ $users = $this->groupManager->get($groupId)->getUsers();
+ // Extract required number
+ $users = array_slice($users, $offset, $limit);
+ $users = array_keys($users);
+ $usersDetails = [];
+ foreach ($users as $userId) {
+ $userData = $this->getUserData($userId);
+ // Do not insert empty entry
+ if(!empty($userData)) {
+ $usersDetails[$userId] = $userData;
+ }
+ }
+ return new DataResponse(['users' => $usersDetails]);
+ }
+
throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
}