aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-04-06 10:52:20 +0200
committerGitHub <noreply@github.com>2018-04-06 10:52:20 +0200
commit4a6e31c91dcbdc2cfd2cae44bf64243c5005fa13 (patch)
treea4fde7f42f905313f2b827e24a91aac6baf86bf5
parent50442b265d676a37babd723386d90bbeda5d6670 (diff)
parenteb4d7fba20f4c1857816188c2aa09bb67eff6429 (diff)
downloadnextcloud-server-4a6e31c91dcbdc2cfd2cae44bf64243c5005fa13.tar.gz
nextcloud-server-4a6e31c91dcbdc2cfd2cae44bf64243c5005fa13.zip
Merge pull request #8904 from nextcloud/ocs-api-get-users-details-per-groups
Api: return users details by groups
-rw-r--r--apps/provisioning_api/appinfo/routes.php2
-rw-r--r--apps/provisioning_api/composer/composer/autoload_classmap.php1
-rw-r--r--apps/provisioning_api/composer/composer/autoload_static.php1
-rw-r--r--apps/provisioning_api/lib/Controller/AUserData.php186
-rw-r--r--apps/provisioning_api/lib/Controller/GroupsController.php135
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php145
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php85
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php10
-rwxr-xr-x[-rw-r--r--]build/autoloaderchecker.sh0
-rw-r--r--build/integration/features/provisioning-v1.feature4
10 files changed, 349 insertions, 220 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/composer/composer/autoload_classmap.php b/apps/provisioning_api/composer/composer/autoload_classmap.php
index 028f6e5c1dd..760eae82978 100644
--- a/apps/provisioning_api/composer/composer/autoload_classmap.php
+++ b/apps/provisioning_api/composer/composer/autoload_classmap.php
@@ -7,6 +7,7 @@ $baseDir = $vendorDir;
return array(
'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
+ 'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir . '/../lib/Controller/AUserData.php',
'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php',
'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
diff --git a/apps/provisioning_api/composer/composer/autoload_static.php b/apps/provisioning_api/composer/composer/autoload_static.php
index b4e6c8e83b0..ccd4d54dccf 100644
--- a/apps/provisioning_api/composer/composer/autoload_static.php
+++ b/apps/provisioning_api/composer/composer/autoload_static.php
@@ -22,6 +22,7 @@ class ComposerStaticInitProvisioning_API
public static $classMap = array (
'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
+ 'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__ . '/..' . '/../lib/Controller/AUserData.php',
'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php',
'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php
new file mode 100644
index 00000000000..82ca98ced8c
--- /dev/null
+++ b/apps/provisioning_api/lib/Controller/AUserData.php
@@ -0,0 +1,186 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Provisioning_API\Controller;
+
+use OC\Accounts\AccountManager;
+use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\AppFramework\OCSController;
+use OCP\Files\NotFoundException;
+use OC_Helper;
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\IRequest;
+use OCP\IUserManager;
+use OCP\IUserSession;
+
+abstract class AUserData extends OCSController {
+
+ /** @var IUserManager */
+ protected $userManager;
+ /** @var IConfig */
+ protected $config;
+ /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
+ protected $groupManager;
+ /** @var IUserSession */
+ protected $userSession;
+ /** @var AccountManager */
+ protected $accountManager;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param IUserManager $userManager
+ * @param IConfig $config
+ * @param IGroupManager $groupManager
+ * @param IUserSession $userSession
+ * @param AccountManager $accountManager
+ */
+ public function __construct(string $appName,
+ IRequest $request,
+ IUserManager $userManager,
+ IConfig $config,
+ IGroupManager $groupManager,
+ IUserSession $userSession,
+ AccountManager $accountManager) {
+ parent::__construct($appName, $request);
+
+ $this->userManager = $userManager;
+ $this->config = $config;
+ $this->groupManager = $groupManager;
+ $this->userSession = $userSession;
+ $this->accountManager = $accountManager;
+ }
+
+ /**
+ * creates a array with all user data
+ *
+ * @param $userId
+ * @return array
+ * @throws OCSException
+ */
+ protected function getUserData(string $userId): array {
+ $currentLoggedInUser = $this->userSession->getUser();
+
+ $data = [];
+
+ // Check if the target user exists
+ $targetUserObject = $this->userManager->get($userId);
+ if($targetUserObject === null) {
+ throw new OCSNotFoundException('User does not exist');
+ }
+
+ // Should be at least Admin Or SubAdmin!
+ if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
+ $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
+ } else {
+ // Check they are looking up themselves
+ if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
+ return $data;
+ }
+ }
+
+ // Get groups data
+ $userAccount = $this->accountManager->getUser($targetUserObject);
+ $groups = $this->groupManager->getUserGroups($targetUserObject);
+ $gids = [];
+ foreach ($groups as $group) {
+ $gids[] = $group->getDisplayName();
+ }
+
+ // Find the data
+ $data['id'] = $targetUserObject->getUID();
+ $data['storageLocation'] = $targetUserObject->getHome();
+ $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
+ $data['backend'] = $targetUserObject->getBackendClassName();
+ $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
+ $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
+ $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
+ $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
+ $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
+ $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
+ $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
+ $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
+ $data['groups'] = $gids;
+ $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang');
+
+ return $data;
+ }
+
+ /**
+ * Get the groups a user is a subadmin of
+ *
+ * @param string $userId
+ * @return array
+ * @throws OCSException
+ */
+ protected function getUserSubAdminGroupsData(string $userId): array {
+ $user = $this->userManager->get($userId);
+ // Check if the user exists
+ if($user === null) {
+ throw new OCSNotFoundException('User does not exist');
+ }
+
+ // Get the subadmin groups
+ $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
+ $groups = [];
+ foreach ($subAdminGroups as $key => $group) {
+ $groups[] = $group->getGID();
+ }
+
+ return $groups;
+ }
+
+ /**
+ * @param string $userId
+ * @return array
+ * @throws \OCP\Files\NotFoundException
+ */
+ protected function fillStorageInfo(string $userId): array {
+ try {
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($userId);
+ $storage = OC_Helper::getStorageInfo('/');
+ $data = [
+ 'free' => $storage['free'],
+ 'used' => $storage['used'],
+ 'total' => $storage['total'],
+ 'relative' => $storage['relative'],
+ 'quota' => $storage['quota'],
+ ];
+ } catch (NotFoundException $ex) {
+ // User fs is not setup yet
+ $user = $this->userManager->get($userId);
+ if ($user === null) {
+ throw new OCSException('User does not exist', 101);
+ }
+ $quota = OC_Helper::computerFileSize($user->getQuota());
+ $data = [
+ 'quota' => $quota ? $quota : 'none',
+ 'used' => 0
+ ];
+ }
+ return $data;
+ }
+
+}
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);
}
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index c8c00fa8592..1a710b592d2 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -12,6 +12,7 @@ declare(strict_types=1);
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Tom Needham <tom@owncloud.com>
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0
*
@@ -34,14 +35,11 @@ namespace OCA\Provisioning_API\Controller;
use OC\Accounts\AccountManager;
use OC\HintException;
use OC\Settings\Mailer\NewUserMailHelper;
-use OC_Helper;
use OCA\Provisioning_API\FederatedFileSharingFactory;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
-use OCP\AppFramework\OCSController;
-use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -52,20 +50,10 @@ use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
-class UsersController extends OCSController {
+class UsersController extends AUserData {
- /** @var IUserManager */
- private $userManager;
- /** @var IConfig */
- private $config;
/** @var IAppManager */
private $appManager;
- /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
- private $groupManager;
- /** @var IUserSession */
- private $userSession;
- /** @var AccountManager */
- private $accountManager;
/** @var ILogger */
private $logger;
/** @var IFactory */
@@ -105,14 +93,15 @@ class UsersController extends OCSController {
NewUserMailHelper $newUserMailHelper,
FederatedFileSharingFactory $federatedFileSharingFactory,
ISecureRandom $secureRandom) {
- parent::__construct($appName, $request);
+ parent::__construct($appName,
+ $request,
+ $userManager,
+ $config,
+ $groupManager,
+ $userSession,
+ $accountManager);
- $this->userManager = $userManager;
- $this->config = $config;
$this->appManager = $appManager;
- $this->groupManager = $groupManager;
- $this->userSession = $userSession;
- $this->accountManager = $accountManager;
$this->logger = $logger;
$this->l10nFactory = $l10nFactory;
$this->newUserMailHelper = $newUserMailHelper;
@@ -225,7 +214,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);
}
}
@@ -335,62 +324,6 @@ class UsersController extends OCSController {
}
/**
- * creates a array with all user data
- *
- * @param $userId
- * @return array
- * @throws OCSException
- */
- protected function getUserData(string $userId): array {
- $currentLoggedInUser = $this->userSession->getUser();
-
- $data = [];
-
- // Check if the target user exists
- $targetUserObject = $this->userManager->get($userId);
- if($targetUserObject === null) {
- throw new OCSException('The requested user could not be found', \OCP\API::RESPOND_NOT_FOUND);
- }
-
- // Should be at least Admin Or SubAdmin!
- if( $this->groupManager->isAdmin($currentLoggedInUser->getUID())
- || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
- $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true');
- } else {
- // Check they are looking up themselves
- if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
- return $data;
- }
- }
-
- // Get groups data
- $userAccount = $this->accountManager->getUser($targetUserObject);
- $groups = $this->groupManager->getUserGroups($targetUserObject);
- $gids = [];
- foreach ($groups as $group) {
- $gids[] = $group->getDisplayName();
- }
-
- // Find the data
- $data['id'] = $targetUserObject->getUID();
- $data['storageLocation'] = $targetUserObject->getHome();
- $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
- $data['backend'] = $targetUserObject->getBackendClassName();
- $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
- $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
- $data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
- $data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
- $data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
- $data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
- $data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
- $data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
- $data['groups'] = $gids;
- $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang');
-
- return $data;
- }
-
- /**
* @NoAdminRequired
* @NoSubAdminRequired
*/
@@ -808,7 +741,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
@@ -859,30 +792,6 @@ class UsersController extends OCSController {
* Get the groups a user is a subadmin of
*
* @param string $userId
- * @return array
- * @throws OCSException
- */
- protected function getUserSubAdminGroupsData(string $userId): array {
- $user = $this->userManager->get($userId);
- // Check if the user exists
- if($user === null) {
- throw new OCSException('User does not exist', 101);
- }
-
- // Get the subadmin groups
- $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
- $groups = [];
- foreach ($subAdminGroups as $key => $group) {
- $groups[] = $group->getGID();
- }
-
- return $groups;
- }
-
- /**
- * Get the groups a user is a subadmin of
- *
- * @param string $userId
* @return DataResponse
* @throws OCSException
*/
@@ -892,38 +801,6 @@ class UsersController extends OCSController {
}
/**
- * @param string $userId
- * @return array
- * @throws \OCP\Files\NotFoundException
- */
- protected function fillStorageInfo(string $userId): array {
- try {
- \OC_Util::tearDownFS();
- \OC_Util::setupFS($userId);
- $storage = OC_Helper::getStorageInfo('/');
- $data = [
- 'free' => $storage['free'],
- 'used' => $storage['used'],
- 'total' => $storage['total'],
- 'relative' => $storage['relative'],
- 'quota' => $storage['quota'],
- ];
- } catch (NotFoundException $ex) {
- // User fs is not setup yet
- $user = $this->userManager->get($userId);
- if ($user === null) {
- throw new OCSException('User does not exist', 101);
- }
- $quota = OC_Helper::computerFileSize($user->getQuota());
- $data = [
- 'quota' => $quota ? $quota : 'none',
- 'used' => 0
- ];
- }
- return $data;
- }
-
- /**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index 352264c7afb..44b440a40b2 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -26,54 +26,67 @@
namespace OCA\Provisioning_API\Tests\Controller;
+use OC\Accounts\AccountManager;
+use OC\Group\Manager;
+use OC\SubAdmin;
use OCA\Provisioning_API\Controller\GroupsController;
-use OCP\IGroupManager;
+use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
+use OCP\IUserManager;
use OCP\IUserSession;
class GroupsControllerTest extends \Test\TestCase {
- /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+
+ /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */
+ protected $request;
+ /** @var IUserManager|PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
+ /** @var IConfig|PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+ /** @var Manager|PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;
- /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserSession|PHPUnit_Framework_MockObject_MockObject */
protected $userSession;
- /** @var \OC\SubAdmin|\PHPUnit_Framework_MockObject_MockObject */
- protected $subAdminManager;
+ /** @var AccountManager|PHPUnit_Framework_MockObject_MockObject */
+ protected $accountManager;
+ /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
+ protected $logger;
- /** @var GroupsController */
+ /** @var GroupsController|PHPUnit_Framework_MockObject_MockObject */
protected $api;
protected function setUp() {
parent::setUp();
- $this->subAdminManager = $this->getMockBuilder('OC\SubAdmin')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->groupManager = $this->createMock(Manager::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->accountManager = $this->createMock(AccountManager::class);
+ $this->logger = $this->createMock(ILogger::class);
+
+ $this->subAdminManager = $this->createMock(SubAdmin::class);
- $this->groupManager = $this->getMockBuilder('OC\Group\Manager')
- ->disableOriginalConstructor()
- ->getMock();
$this->groupManager
- ->method('getSubAdmin')
- ->willReturn($this->subAdminManager);
-
- $this->userSession = $this->getMockBuilder(IUserSession::class)
- ->disableOriginalConstructor()
+ ->method('getSubAdmin')
+ ->willReturn($this->subAdminManager);
+
+ $this->api = $this->getMockBuilder(GroupsController::class)
+ ->setConstructorArgs([
+ 'provisioning_api',
+ $this->request,
+ $this->userManager,
+ $this->config,
+ $this->groupManager,
+ $this->userSession,
+ $this->accountManager,
+ $this->logger
+ ])
+ ->setMethods(['fillStorageInfo'])
->getMock();
- $request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $logger = $this->createMock(ILogger::class);
-
- $this->api = new GroupsController(
- 'provisioning_api',
- $request,
- $this->groupManager,
- $this->userSession,
- $logger
- );
}
/**
@@ -141,10 +154,10 @@ class GroupsControllerTest extends \Test\TestCase {
public function dataGetGroups() {
return [
- [null, null, null],
- ['foo', null, null],
- [null, 1, null],
- [null, null, 2],
+ [null, 0, 0],
+ ['foo', 0, 0],
+ [null, 1, 0],
+ [null, 0, 2],
['foo', 1, 2],
];
}
@@ -224,7 +237,7 @@ class GroupsControllerTest extends \Test\TestCase {
/**
* @expectedException \OCP\AppFramework\OCS\OCSException
- * @expectedExceptionCode 997
+ * @expectedExceptionCode 403
*/
public function testGetGroupAsIrrelevantSubadmin() {
$group = $this->createGroup('group');
@@ -269,7 +282,7 @@ class GroupsControllerTest extends \Test\TestCase {
/**
* @expectedException \OCP\AppFramework\OCS\OCSException
- * @expectedExceptionCode 998
+ * @expectedExceptionCode 404
* @expectedExceptionMessage The requested group could not be found
*/
public function testGetGroupNonExisting() {
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 3f2cf3b1105..3d6ab8f3ebf 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -640,8 +640,8 @@ class UsersControllerTest extends TestCase {
/**
* @expectedException \OCP\AppFramework\OCS\OCSException
- * @expectedExceptionCode 998
- * @expectedExceptionMessage The requested user could not be found
+ * @expectedExceptionCode 404
+ * @expectedExceptionMessage User does not exist
*/
public function testGetUserTargetDoesNotExist() {
$loggedInUser = $this->getMockBuilder(IUser::class)
@@ -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
@@ -2818,7 +2818,7 @@ class UsersControllerTest extends TestCase {
/**
* @expectedException \OCP\AppFramework\OCS\OCSException
- * @expectedExceptionCode 101
+ * @expectedExceptionCode 404
* @expectedExceptionMessage User does not exist
*/
public function testGetUserSubAdminGroupsNotExistingTargetUser() {
diff --git a/build/autoloaderchecker.sh b/build/autoloaderchecker.sh
index ffa157f6c80..ffa157f6c80 100644..100755
--- a/build/autoloaderchecker.sh
+++ b/build/autoloaderchecker.sh
diff --git a/build/integration/features/provisioning-v1.feature b/build/integration/features/provisioning-v1.feature
index 84e2e30baa1..647bcb1704b 100644
--- a/build/integration/features/provisioning-v1.feature
+++ b/build/integration/features/provisioning-v1.feature
@@ -5,7 +5,7 @@ Feature: provisioning
Scenario: Getting an not existing user
Given As an "admin"
When sending "GET" to "/cloud/users/test"
- Then the OCS status code should be "998"
+ Then the OCS status code should be "404"
And the HTTP status code should be "200"
Scenario: Listing all users
@@ -264,7 +264,7 @@ Feature: provisioning
And user "not-user" does not exist
And group "new-group" exists
When sending "GET" to "/cloud/users/not-user/subadmins"
- Then the OCS status code should be "101"
+ Then the OCS status code should be "404"
And the HTTP status code should be "200"
Scenario: Getting subadmin users of a group