Fix Warnings Provisioning API

* OC_OCS_Result is deprecated
* getMock is deprecated in phpunit 5.4
This commit is contained in:
Roeland Jago Douma 2016-07-12 08:38:56 +02:00
parent e29835a702
commit f9e0e3d972
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
6 changed files with 417 additions and 330 deletions

View File

@ -26,7 +26,6 @@
namespace OCA\Provisioning_API; namespace OCA\Provisioning_API;
use OC\OCSClient; use OC\OCSClient;
use \OC_OCS_Result;
use \OC_App; use \OC_App;
class Apps { class Apps {
@ -46,7 +45,7 @@ class Apps {
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getApps($parameters) { public function getApps($parameters) {
$apps = OC_App::listAllApps(false, true, $this->ocsClient); $apps = OC_App::listAllApps(false, true, $this->ocsClient);
@ -58,55 +57,55 @@ class Apps {
if($filter){ if($filter){
switch($filter){ switch($filter){
case 'enabled': case 'enabled':
return new OC_OCS_Result(array('apps' => \OC_App::getEnabledApps())); return new \OC\OCS\Result(array('apps' => \OC_App::getEnabledApps()));
break; break;
case 'disabled': case 'disabled':
$enabled = OC_App::getEnabledApps(); $enabled = OC_App::getEnabledApps();
return new OC_OCS_Result(array('apps' => array_diff($list, $enabled))); return new \OC\OCS\Result(array('apps' => array_diff($list, $enabled)));
break; break;
default: default:
// Invalid filter variable // Invalid filter variable
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
break; break;
} }
} else { } else {
return new OC_OCS_Result(array('apps' => $list)); return new \OC\OCS\Result(array('apps' => $list));
} }
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getAppInfo($parameters) { public function getAppInfo($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$info = \OCP\App::getAppInfo($app); $info = \OCP\App::getAppInfo($app);
if(!is_null($info)) { if(!is_null($info)) {
return new OC_OCS_Result(OC_App::getAppInfo($app)); return new \OC\OCS\Result(OC_App::getAppInfo($app));
} else { } else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found'); return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found');
} }
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function enable($parameters) { public function enable($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$this->appManager->enableApp($app); $this->appManager->enableApp($app);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function disable($parameters) { public function disable($parameters) {
$app = $parameters['appid']; $app = $parameters['appid'];
$this->appManager->disableApp($app); $this->appManager->disableApp($app);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
} }

View File

@ -25,7 +25,6 @@
namespace OCA\Provisioning_API; namespace OCA\Provisioning_API;
use \OC_OCS_Result;
use OCP\IGroup; use OCP\IGroup;
use OCP\IUser; use OCP\IUser;
@ -57,7 +56,7 @@ class Groups{
* returns a list of groups * returns a list of groups
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getGroups($parameters) { public function getGroups($parameters) {
$search = $this->request->getParam('search', ''); $search = $this->request->getParam('search', '');
@ -77,27 +76,27 @@ class Groups{
return $group->getGID(); return $group->getGID();
}, $groups); }, $groups);
return new OC_OCS_Result(['groups' => $groups]); return new \OC\OCS\Result(['groups' => $groups]);
} }
/** /**
* returns an array of users in the group specified * returns an array of users in the group specified
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getGroup($parameters) { public function getGroup($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$groupId = $parameters['groupid']; $groupId = $parameters['groupid'];
// Check the group exists // Check the group exists
if(!$this->groupManager->groupExists($groupId)) { if(!$this->groupManager->groupExists($groupId)) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found'); return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found');
} }
$isSubadminOfGroup = false; $isSubadminOfGroup = false;
@ -115,9 +114,9 @@ class Groups{
return $user->getUID(); return $user->getUID();
}, $users); }, $users);
$users = array_values($users); $users = array_values($users);
return new OC_OCS_Result(['users' => $users]); return new \OC\OCS\Result(['users' => $users]);
} else { } else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'User does not have access to specified group'); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'User does not have access to specified group');
} }
} }
@ -125,49 +124,49 @@ class Groups{
* creates a new group * creates a new group
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function addGroup($parameters) { public function addGroup($parameters) {
// Validate name // Validate name
$groupId = $this->request->getParam('groupid', ''); $groupId = $this->request->getParam('groupid', '');
if(empty($groupId)){ if(empty($groupId)){
\OCP\Util::writeLog('provisioning_api', 'Group name not supplied', \OCP\Util::ERROR); \OCP\Util::writeLog('provisioning_api', 'Group name not supplied', \OCP\Util::ERROR);
return new OC_OCS_Result(null, 101, 'Invalid group name'); return new \OC\OCS\Result(null, 101, 'Invalid group name');
} }
// Check if it exists // Check if it exists
if($this->groupManager->groupExists($groupId)){ if($this->groupManager->groupExists($groupId)){
return new OC_OCS_Result(null, 102); return new \OC\OCS\Result(null, 102);
} }
$this->groupManager->createGroup($groupId); $this->groupManager->createGroup($groupId);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function deleteGroup($parameters) { public function deleteGroup($parameters) {
// Check it exists // Check it exists
if(!$this->groupManager->groupExists($parameters['groupid'])){ if(!$this->groupManager->groupExists($parameters['groupid'])){
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} else if($parameters['groupid'] === 'admin' || !$this->groupManager->get($parameters['groupid'])->delete()){ } else if($parameters['groupid'] === 'admin' || !$this->groupManager->get($parameters['groupid'])->delete()){
// Cannot delete admin group // Cannot delete admin group
return new OC_OCS_Result(null, 102); return new \OC\OCS\Result(null, 102);
} else { } else {
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getSubAdminsOfGroup($parameters) { public function getSubAdminsOfGroup($parameters) {
$group = $parameters['groupid']; $group = $parameters['groupid'];
// Check group exists // Check group exists
$targetGroup = $this->groupManager->get($group); $targetGroup = $this->groupManager->get($group);
if($targetGroup === null) { if($targetGroup === null) {
return new OC_OCS_Result(null, 101, 'Group does not exist'); return new \OC\OCS\Result(null, 101, 'Group does not exist');
} }
$subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
@ -177,7 +176,7 @@ class Groups{
$uids[] = $user->getUID(); $uids[] = $user->getUID();
} }
return new OC_OCS_Result($uids); return new \OC\OCS\Result($uids);
} }
} }

View File

@ -28,7 +28,6 @@
namespace OCA\Provisioning_API; namespace OCA\Provisioning_API;
use \OC_OCS_Result;
use \OC_Helper; use \OC_Helper;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IConfig; use OCP\IConfig;
@ -72,7 +71,7 @@ class Users {
/** /**
* returns a list of users * returns a list of users
* *
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getUsers() { public function getUsers() {
$search = !empty($_GET['search']) ? $_GET['search'] : ''; $search = !empty($_GET['search']) ? $_GET['search'] : '';
@ -82,7 +81,7 @@ class Users {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
// Admin? Or SubAdmin? // Admin? Or SubAdmin?
@ -107,17 +106,17 @@ class Users {
$users = array_slice($users, $offset, $limit); $users = array_slice($users, $offset, $limit);
} else { } else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$users = array_keys($users); $users = array_keys($users);
return new OC_OCS_Result([ return new \OC\OCS\Result([
'users' => $users 'users' => $users
]); ]);
} }
/** /**
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function addUser() { public function addUser() {
$userId = isset($_POST['userid']) ? $_POST['userid'] : null; $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
@ -128,26 +127,26 @@ class Users {
$subAdminManager = $this->groupManager->getSubAdmin(); $subAdminManager = $this->groupManager->getSubAdmin();
if (!$isAdmin && !$subAdminManager->isSubAdmin($user)) { if (!$isAdmin && !$subAdminManager->isSubAdmin($user)) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
if($this->userManager->userExists($userId)) { if($this->userManager->userExists($userId)) {
$this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
return new OC_OCS_Result(null, 102, 'User already exists'); return new \OC\OCS\Result(null, 102, 'User already exists');
} }
if(is_array($groups)) { if(is_array($groups)) {
foreach ($groups as $group) { foreach ($groups as $group) {
if(!$this->groupManager->groupExists($group)){ if(!$this->groupManager->groupExists($group)){
return new OC_OCS_Result(null, 104, 'group '.$group.' does not exist'); return new \OC\OCS\Result(null, 104, 'group '.$group.' does not exist');
} }
if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) {
return new OC_OCS_Result(null, 105, 'insufficient privileges for group '. $group); return new \OC\OCS\Result(null, 105, 'insufficient privileges for group '. $group);
} }
} }
} else { } else {
if(!$isAdmin) { if(!$isAdmin) {
return new OC_OCS_Result(null, 106, 'no group specified (required for subadmins)'); return new \OC\OCS\Result(null, 106, 'no group specified (required for subadmins)');
} }
} }
@ -161,10 +160,10 @@ class Users {
$this->logger->info('Added userid '.$userId.' to group '.$group, ['app' => 'ocs_api']); $this->logger->info('Added userid '.$userId.' to group '.$group, ['app' => 'ocs_api']);
} }
} }
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']);
return new OC_OCS_Result(null, 101, 'Bad request'); return new \OC\OCS\Result(null, 101, 'Bad request');
} }
} }
@ -172,7 +171,7 @@ class Users {
* gets user info * gets user info
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getUser($parameters) { public function getUser($parameters) {
$userId = $parameters['userid']; $userId = $parameters['userid'];
@ -180,7 +179,7 @@ class Users {
// Check if user is logged in // Check if user is logged in
$currentLoggedInUser = $this->userSession->getUser(); $currentLoggedInUser = $this->userSession->getUser();
if ($currentLoggedInUser === null) { if ($currentLoggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$data = []; $data = [];
@ -188,7 +187,7 @@ class Users {
// Check if the target user exists // Check if the target user exists
$targetUserObject = $this->userManager->get($userId); $targetUserObject = $this->userManager->get($userId);
if($targetUserObject === null) { if($targetUserObject === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found'); return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
} }
// Admin? Or SubAdmin? // Admin? Or SubAdmin?
@ -198,7 +197,7 @@ class Users {
} else { } else {
// Check they are looking up themselves // Check they are looking up themselves
if($currentLoggedInUser->getUID() !== $userId) { if($currentLoggedInUser->getUID() !== $userId) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
} }
@ -207,14 +206,14 @@ class Users {
$data['email'] = $targetUserObject->getEMailAddress(); $data['email'] = $targetUserObject->getEMailAddress();
$data['displayname'] = $targetUserObject->getDisplayName(); $data['displayname'] = $targetUserObject->getDisplayName();
return new OC_OCS_Result($data); return new \OC\OCS\Result($data);
} }
/** /**
* edit users * edit users
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function editUser($parameters) { public function editUser($parameters) {
/** @var string $targetUserId */ /** @var string $targetUserId */
@ -223,14 +222,15 @@ class Users {
// Check if user is logged in // Check if user is logged in
$currentLoggedInUser = $this->userSession->getUser(); $currentLoggedInUser = $this->userSession->getUser();
if ($currentLoggedInUser === null) { if ($currentLoggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$targetUser = $this->userManager->get($targetUserId); $targetUser = $this->userManager->get($targetUserId);
if($targetUser === null) { if($targetUser === null) {
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
$permittedFields = [];
if($targetUserId === $currentLoggedInUser->getUID()) { if($targetUserId === $currentLoggedInUser->getUID()) {
// Editing self (display, email) // Editing self (display, email)
$permittedFields[] = 'display'; $permittedFields[] = 'display';
@ -252,12 +252,12 @@ class Users {
$permittedFields[] = 'email'; $permittedFields[] = 'email';
} else { } else {
// No rights // No rights
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
} }
// Check if permitted to edit this field // Check if permitted to edit this field
if(!in_array($parameters['_put']['key'], $permittedFields)) { if(!in_array($parameters['_put']['key'], $permittedFields)) {
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
// Process the edit // Process the edit
switch($parameters['_put']['key']) { switch($parameters['_put']['key']) {
@ -273,7 +273,7 @@ class Users {
$quota = \OCP\Util::computerFileSize($quota); $quota = \OCP\Util::computerFileSize($quota);
} }
if ($quota === false) { if ($quota === false) {
return new OC_OCS_Result(null, 103, "Invalid quota value {$parameters['_put']['value']}"); return new \OC\OCS\Result(null, 103, "Invalid quota value {$parameters['_put']['value']}");
} }
if($quota === 0) { if($quota === 0) {
$quota = 'default'; $quota = 'default';
@ -292,50 +292,49 @@ class Users {
if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) {
$targetUser->setEMailAddress($parameters['_put']['value']); $targetUser->setEMailAddress($parameters['_put']['value']);
} else { } else {
return new OC_OCS_Result(null, 102); return new \OC\OCS\Result(null, 102);
} }
break; break;
default: default:
return new OC_OCS_Result(null, 103); return new \OC\OCS\Result(null, 103);
break;
} }
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function deleteUser($parameters) { public function deleteUser($parameters) {
// Check if user is logged in // Check if user is logged in
$currentLoggedInUser = $this->userSession->getUser(); $currentLoggedInUser = $this->userSession->getUser();
if ($currentLoggedInUser === null) { if ($currentLoggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$targetUser = $this->userManager->get($parameters['userid']); $targetUser = $this->userManager->get($parameters['userid']);
if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} }
// If not permitted // If not permitted
$subAdminManager = $this->groupManager->getSubAdmin(); $subAdminManager = $this->groupManager->getSubAdmin();
if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
// Go ahead with the delete // Go ahead with the delete
if($targetUser->delete()) { if($targetUser->delete()) {
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} else { } else {
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} }
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function disableUser($parameters) { public function disableUser($parameters) {
return $this->setEnabled($parameters, false); return $this->setEnabled($parameters, false);
@ -343,7 +342,7 @@ class Users {
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function enableUser($parameters) { public function enableUser($parameters) {
return $this->setEnabled($parameters, true); return $this->setEnabled($parameters, true);
@ -352,50 +351,50 @@ class Users {
/** /**
* @param array $parameters * @param array $parameters
* @param bool $value * @param bool $value
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
private function setEnabled($parameters, $value) { private function setEnabled($parameters, $value) {
// Check if user is logged in // Check if user is logged in
$currentLoggedInUser = $this->userSession->getUser(); $currentLoggedInUser = $this->userSession->getUser();
if ($currentLoggedInUser === null) { if ($currentLoggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$targetUser = $this->userManager->get($parameters['userid']); $targetUser = $this->userManager->get($parameters['userid']);
if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} }
// If not permitted // If not permitted
$subAdminManager = $this->groupManager->getSubAdmin(); $subAdminManager = $this->groupManager->getSubAdmin();
if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
// enable/disable the user now // enable/disable the user now
$targetUser->setEnabled($value); $targetUser->setEnabled($value);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getUsersGroups($parameters) { public function getUsersGroups($parameters) {
// Check if user is logged in // Check if user is logged in
$loggedInUser = $this->userSession->getUser(); $loggedInUser = $this->userSession->getUser();
if ($loggedInUser === null) { if ($loggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$targetUser = $this->userManager->get($parameters['userid']); $targetUser = $this->userManager->get($parameters['userid']);
if($targetUser === null) { if($targetUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND); return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND);
} }
if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
// Self lookup or admin lookup // Self lookup or admin lookup
return new OC_OCS_Result([ return new \OC\OCS\Result([
'groups' => $this->groupManager->getUserGroupIds($targetUser) 'groups' => $this->groupManager->getUserGroupIds($targetUser)
]); ]);
} else { } else {
@ -412,10 +411,10 @@ class Users {
$getSubAdminsGroups, $getSubAdminsGroups,
$this->groupManager->getUserGroupIds($targetUser) $this->groupManager->getUserGroupIds($targetUser)
); );
return new OC_OCS_Result(array('groups' => $groups)); return new \OC\OCS\Result(array('groups' => $groups));
} else { } else {
// Not permitted // Not permitted
return new OC_OCS_Result(null, 997); return new \OC\OCS\Result(null, 997);
} }
} }
@ -423,76 +422,76 @@ class Users {
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function addToGroup($parameters) { public function addToGroup($parameters) {
// Check if user is logged in // Check if user is logged in
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
// Check they're an admin // Check they're an admin
if(!$this->groupManager->isAdmin($user->getUID())) { if(!$this->groupManager->isAdmin($user->getUID())) {
// This user doesn't have rights to add a user to this group // This user doesn't have rights to add a user to this group
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$groupId = !empty($_POST['groupid']) ? $_POST['groupid'] : null; $groupId = !empty($_POST['groupid']) ? $_POST['groupid'] : null;
if($groupId === null) { if($groupId === null) {
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} }
$group = $this->groupManager->get($groupId); $group = $this->groupManager->get($groupId);
$targetUser = $this->userManager->get($parameters['userid']); $targetUser = $this->userManager->get($parameters['userid']);
if($group === null) { if($group === null) {
return new OC_OCS_Result(null, 102); return new \OC\OCS\Result(null, 102);
} }
if($targetUser === null) { if($targetUser === null) {
return new OC_OCS_Result(null, 103); return new \OC\OCS\Result(null, 103);
} }
// Add user to group // Add user to group
$group->addUser($targetUser); $group->addUser($targetUser);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function removeFromGroup($parameters) { public function removeFromGroup($parameters) {
// Check if user is logged in // Check if user is logged in
$loggedInUser = $this->userSession->getUser(); $loggedInUser = $this->userSession->getUser();
if ($loggedInUser === null) { if ($loggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null; $group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null;
if($group === null) { if($group === null) {
return new OC_OCS_Result(null, 101); return new \OC\OCS\Result(null, 101);
} }
$group = $this->groupManager->get($group); $group = $this->groupManager->get($group);
if($group === null) { if($group === null) {
return new OC_OCS_Result(null, 102); return new \OC\OCS\Result(null, 102);
} }
$targetUser = $this->userManager->get($parameters['userid']); $targetUser = $this->userManager->get($parameters['userid']);
if($targetUser === null) { if($targetUser === null) {
return new OC_OCS_Result(null, 103); return new \OC\OCS\Result(null, 103);
} }
// If they're not an admin, check they are a subadmin of the group in question // If they're not an admin, check they are a subadmin of the group in question
$subAdminManager = $this->groupManager->getSubAdmin(); $subAdminManager = $this->groupManager->getSubAdmin();
if(!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) { if(!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) {
return new OC_OCS_Result(null, 104); return new \OC\OCS\Result(null, 104);
} }
// Check they aren't removing themselves from 'admin' or their 'subadmin; group // Check they aren't removing themselves from 'admin' or their 'subadmin; group
if($parameters['userid'] === $loggedInUser->getUID()) { if($parameters['userid'] === $loggedInUser->getUID()) {
if($this->groupManager->isAdmin($loggedInUser->getUID())) { if($this->groupManager->isAdmin($loggedInUser->getUID())) {
if($group->getGID() === 'admin') { if($group->getGID() === 'admin') {
return new OC_OCS_Result(null, 105, 'Cannot remove yourself from the admin group'); return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from the admin group');
} }
} else { } else {
// Not an admin, check they are not removing themself from their subadmin group // Not an admin, check they are not removing themself from their subadmin group
@ -502,21 +501,21 @@ class Users {
} }
if(in_array($group->getGID(), $subAdminGroups, true)) { if(in_array($group->getGID(), $subAdminGroups, true)) {
return new OC_OCS_Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin'); return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin');
} }
} }
} }
// Remove user from group // Remove user from group
$group->removeUser($targetUser); $group->removeUser($targetUser);
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
/** /**
* Creates a subadmin * Creates a subadmin
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function addSubAdmin($parameters) { public function addSubAdmin($parameters) {
$group = $this->groupManager->get($_POST['groupid']); $group = $this->groupManager->get($_POST['groupid']);
@ -524,28 +523,28 @@ class Users {
// Check if the user exists // Check if the user exists
if($user === null) { if($user === null) {
return new OC_OCS_Result(null, 101, 'User does not exist'); return new \OC\OCS\Result(null, 101, 'User does not exist');
} }
// Check if group exists // Check if group exists
if($group === null) { if($group === null) {
return new OC_OCS_Result(null, 102, 'Group:'.$_POST['groupid'].' does not exist'); return new \OC\OCS\Result(null, 102, 'Group:'.$_POST['groupid'].' does not exist');
} }
// Check if trying to make subadmin of admin group // Check if trying to make subadmin of admin group
if(strtolower($_POST['groupid']) === 'admin') { if(strtolower($_POST['groupid']) === 'admin') {
return new OC_OCS_Result(null, 103, 'Cannot create subadmins for admin group'); return new \OC\OCS\Result(null, 103, 'Cannot create subadmins for admin group');
} }
$subAdminManager = $this->groupManager->getSubAdmin(); $subAdminManager = $this->groupManager->getSubAdmin();
// We cannot be subadmin twice // We cannot be subadmin twice
if ($subAdminManager->isSubAdminofGroup($user, $group)) { if ($subAdminManager->isSubAdminofGroup($user, $group)) {
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} }
// Go // Go
if($subAdminManager->createSubAdmin($user, $group)) { if($subAdminManager->createSubAdmin($user, $group)) {
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} else { } else {
return new OC_OCS_Result(null, 103, 'Unknown error occurred'); return new \OC\OCS\Result(null, 103, 'Unknown error occurred');
} }
} }
@ -553,7 +552,7 @@ class Users {
* Removes a subadmin from a group * Removes a subadmin from a group
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function removeSubAdmin($parameters) { public function removeSubAdmin($parameters) {
$group = $this->groupManager->get($parameters['_delete']['groupid']); $group = $this->groupManager->get($parameters['_delete']['groupid']);
@ -562,22 +561,22 @@ class Users {
// Check if the user exists // Check if the user exists
if($user === null) { if($user === null) {
return new OC_OCS_Result(null, 101, 'User does not exist'); return new \OC\OCS\Result(null, 101, 'User does not exist');
} }
// Check if the group exists // Check if the group exists
if($group === null) { if($group === null) {
return new OC_OCS_Result(null, 101, 'Group does not exist'); return new \OC\OCS\Result(null, 101, 'Group does not exist');
} }
// Check if they are a subadmin of this said group // Check if they are a subadmin of this said group
if(!$subAdminManager->isSubAdminofGroup($user, $group)) { if(!$subAdminManager->isSubAdminofGroup($user, $group)) {
return new OC_OCS_Result(null, 102, 'User is not a subadmin of this group'); return new \OC\OCS\Result(null, 102, 'User is not a subadmin of this group');
} }
// Go // Go
if($subAdminManager->deleteSubAdmin($user, $group)) { if($subAdminManager->deleteSubAdmin($user, $group)) {
return new OC_OCS_Result(null, 100); return new \OC\OCS\Result(null, 100);
} else { } else {
return new OC_OCS_Result(null, 103, 'Unknown error occurred'); return new \OC\OCS\Result(null, 103, 'Unknown error occurred');
} }
} }
@ -585,13 +584,13 @@ class Users {
* Get the groups a user is a subadmin of * Get the groups a user is a subadmin of
* *
* @param array $parameters * @param array $parameters
* @return OC_OCS_Result * @return \OC\OCS\Result
*/ */
public function getUserSubAdminGroups($parameters) { public function getUserSubAdminGroups($parameters) {
$user = $this->userManager->get($parameters['userid']); $user = $this->userManager->get($parameters['userid']);
// Check if the user exists // Check if the user exists
if($user === null) { if($user === null) {
return new OC_OCS_Result(null, 101, 'User does not exist'); return new \OC\OCS\Result(null, 101, 'User does not exist');
} }
// Get the subadmin groups // Get the subadmin groups
@ -601,9 +600,9 @@ class Users {
} }
if(!$groups) { if(!$groups) {
return new OC_OCS_Result(null, 102, 'Unknown error occurred'); return new \OC\OCS\Result(null, 102, 'Unknown error occurred');
} else { } else {
return new OC_OCS_Result($groups); return new \OC\OCS\Result($groups);
} }
} }

View File

@ -65,13 +65,13 @@ class AppsTest extends TestCase {
public function testGetAppInfo() { public function testGetAppInfo() {
$result = $this->api->getAppInfo(['appid' => 'provisioning_api']); $result = $this->api->getAppInfo(['appid' => 'provisioning_api']);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
} }
public function testGetAppInfoOnBadAppID() { public function testGetAppInfoOnBadAppID() {
$result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']); $result = $this->api->getAppInfo(['appid' => 'not_provisioning_api']);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode()); $this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode());
} }

View File

@ -57,8 +57,12 @@ class GroupsTest extends \Test\TestCase {
->method('getSubAdmin') ->method('getSubAdmin')
->willReturn($this->subAdminManager); ->willReturn($this->subAdminManager);
$this->userSession = $this->getMock('OCP\IUserSession'); $this->userSession = $this->getMockBuilder('OCP\IUserSession')
$this->request = $this->getMock('OCP\IRequest'); ->disableOriginalConstructor()
->getMock();
$this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->api = new Groups( $this->api = new Groups(
$this->groupManager, $this->groupManager,
$this->userSession, $this->userSession,
@ -71,7 +75,7 @@ class GroupsTest extends \Test\TestCase {
* @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject * @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject
*/ */
private function createGroup($gid) { private function createGroup($gid) {
$group = $this->getMock('OCP\IGroup'); $group = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
$group $group
->method('getGID') ->method('getGID')
->willReturn($gid); ->willReturn($gid);
@ -83,7 +87,7 @@ class GroupsTest extends \Test\TestCase {
* @return \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject * @return \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject
*/ */
private function createUser($uid) { private function createUser($uid) {
$user = $this->getMock('OCP\IUser'); $user = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock();
$user $user
->method('getUID') ->method('getUID')
->willReturn($uid); ->willReturn($uid);
@ -163,7 +167,7 @@ class GroupsTest extends \Test\TestCase {
->willReturn($groups); ->willReturn($groups);
$result = $this->api->getGroups([]); $result = $this->api->getGroups([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$this->assertEquals(['group1', 'group2'], $result->getData()['groups']); $this->assertEquals(['group1', 'group2'], $result->getData()['groups']);
} }
@ -171,7 +175,7 @@ class GroupsTest extends \Test\TestCase {
public function testGetGroupAsUser() { public function testGetGroupAsUser() {
$result = $this->api->getGroup([]); $result = $this->api->getGroup([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode()); $this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode());
@ -200,7 +204,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'group', 'groupid' => 'group',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$this->assertEquals(1, sizeof($result->getData()), 'Asserting the result data array only has the "users" key'); $this->assertEquals(1, sizeof($result->getData()), 'Asserting the result data array only has the "users" key');
$this->assertArrayHasKey('users', $result->getData()); $this->assertArrayHasKey('users', $result->getData());
@ -225,7 +229,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'group', 'groupid' => 'group',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode()); $this->assertEquals(API::RESPOND_UNAUTHORISED, $result->getStatusCode());
} }
@ -253,7 +257,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'group', 'groupid' => 'group',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$this->assertEquals(1, sizeof($result->getData()), 'Asserting the result data array only has the "users" key'); $this->assertEquals(1, sizeof($result->getData()), 'Asserting the result data array only has the "users" key');
$this->assertArrayHasKey('users', $result->getData()); $this->assertArrayHasKey('users', $result->getData());
@ -267,7 +271,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => $this->getUniqueID() 'groupid' => $this->getUniqueID()
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode()); $this->assertEquals(API::RESPOND_NOT_FOUND, $result->getStatusCode());
$this->assertEquals('The requested group could not be found', $result->getMeta()['message']); $this->assertEquals('The requested group could not be found', $result->getMeta()['message']);
@ -278,7 +282,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'NonExistingGroup', 'groupid' => 'NonExistingGroup',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode()); $this->assertEquals(101, $result->getStatusCode());
$this->assertEquals('Group does not exist', $result->getMeta()['message']); $this->assertEquals('Group does not exist', $result->getMeta()['message']);
@ -304,7 +308,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'GroupWithSubAdmins', 'groupid' => 'GroupWithSubAdmins',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData()); $this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData());
} }
@ -327,7 +331,7 @@ class GroupsTest extends \Test\TestCase {
'groupid' => 'GroupWithOutSubAdmins', 'groupid' => 'GroupWithOutSubAdmins',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
$this->assertEquals([], $result->getData()); $this->assertEquals([], $result->getData());
} }
@ -340,7 +344,7 @@ class GroupsTest extends \Test\TestCase {
$result = $this->api->addGroup([]); $result = $this->api->addGroup([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode()); $this->assertEquals(101, $result->getStatusCode());
$this->assertEquals('Invalid group name', $result->getMeta()['message']); $this->assertEquals('Invalid group name', $result->getMeta()['message']);
@ -359,7 +363,7 @@ class GroupsTest extends \Test\TestCase {
$result = $this->api->addGroup([]); $result = $this->api->addGroup([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(102, $result->getStatusCode()); $this->assertEquals(102, $result->getStatusCode());
} }
@ -381,7 +385,7 @@ class GroupsTest extends \Test\TestCase {
->with('NewGroup'); ->with('NewGroup');
$result = $this->api->addGroup([]); $result = $this->api->addGroup([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
} }
@ -402,7 +406,7 @@ class GroupsTest extends \Test\TestCase {
->with('Iñtërnâtiônàlizætiøn'); ->with('Iñtërnâtiônàlizætiøn');
$result = $this->api->addGroup([]); $result = $this->api->addGroup([]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
} }
@ -410,7 +414,7 @@ class GroupsTest extends \Test\TestCase {
$result = $this->api->deleteGroup([ $result = $this->api->deleteGroup([
'groupid' => 'NonExistingGroup' 'groupid' => 'NonExistingGroup'
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode()); $this->assertEquals(101, $result->getStatusCode());
} }
@ -424,7 +428,7 @@ class GroupsTest extends \Test\TestCase {
$result = $this->api->deleteGroup([ $result = $this->api->deleteGroup([
'groupid' => 'admin' 'groupid' => 'admin'
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertFalse($result->succeeded()); $this->assertFalse($result->succeeded());
$this->assertEquals(102, $result->getStatusCode()); $this->assertEquals(102, $result->getStatusCode());
} }
@ -448,7 +452,7 @@ class GroupsTest extends \Test\TestCase {
$result = $this->api->deleteGroup([ $result = $this->api->deleteGroup([
'groupid' => 'ExistingGroup', 'groupid' => 'ExistingGroup',
]); ]);
$this->assertInstanceOf('OC_OCS_Result', $result); $this->assertInstanceOf('\OC\OCS\Result', $result);
$this->assertTrue($result->succeeded()); $this->assertTrue($result->succeeded());
} }
} }

File diff suppressed because it is too large Load Diff