Combine OCS API getUser method code into provisioning_api app

Fixes #13002

Move the cloud/users/{userid} code in total to the provisioning API.
This commit is contained in:
Roeland Jago Douma 2015-10-08 21:47:30 +02:00
parent ef4278cfa9
commit 002e9c76cd
3 changed files with 10 additions and 80 deletions

View File

@ -115,46 +115,28 @@ class Users {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
$data = [];
// Admin? Or SubAdmin? // Admin? Or SubAdmin?
if($this->groupManager->isAdmin($user->getUID()) || OC_SubAdmin::isUserAccessible($user->getUID(), $userId)) { if($this->groupManager->isAdmin($user->getUID()) || OC_SubAdmin::isUserAccessible($user->getUID(), $userId)) {
// Check they exist // Check they exist
if(!$this->userManager->userExists($userId)) { if(!$this->userManager->userExists($userId)) {
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');
} }
// Show all $data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true');
$return = [
'email',
'enabled',
];
if($user->getUID() !== $userId) {
$return[] = 'quota';
}
} else { } else {
// Check they are looking up themselves // Check they are looking up themselves
if($user->getUID() !== $userId) { if($user->getUID() !== $userId) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
} }
// Return some additional information compared to the core route
$return = array(
'email',
'displayname',
);
} }
// Find the data // Find the data
$data = []; $data['quota'] = self::fillStorageInfo($userId);
$data = self::fillStorageInfo($userId, $data);
$data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true');
$data['email'] = $this->config->getUserValue($userId, 'settings', 'email'); $data['email'] = $this->config->getUserValue($userId, 'settings', 'email');
$data['displayname'] = $this->userManager->get($parameters['userid'])->getDisplayName(); $data['displayname'] = $this->userManager->get($userId)->getDisplayName();
// Return the appropriate data return new OC_OCS_Result($data);
$responseData = array();
foreach($return as $key) {
$responseData[$key] = $data[$key];
}
return new OC_OCS_Result($responseData);
} }
/** /**
@ -473,19 +455,20 @@ class Users {
* @return mixed * @return mixed
* @throws \OCP\Files\NotFoundException * @throws \OCP\Files\NotFoundException
*/ */
private static function fillStorageInfo($userId, $data) { private static function fillStorageInfo($userId) {
$data = [];
try { try {
\OC_Util::tearDownFS(); \OC_Util::tearDownFS();
\OC_Util::setupFS($userId); \OC_Util::setupFS($userId);
$storage = OC_Helper::getStorageInfo('/'); $storage = OC_Helper::getStorageInfo('/');
$data['quota'] = [ $data = [
'free' => $storage['free'], 'free' => $storage['free'],
'used' => $storage['used'], 'used' => $storage['used'],
'total' => $storage['total'], 'total' => $storage['total'],
'relative' => $storage['relative'], 'relative' => $storage['relative'],
]; ];
} catch (NotFoundException $ex) { } catch (NotFoundException $ex) {
$data['quota'] = []; $data = [];
} }
return $data; return $data;
} }

View File

@ -42,52 +42,6 @@ class OC_OCS_Cloud {
return new OC_OCS_Result($result); return new OC_OCS_Result($result);
} }
/**
* gets user info
*
* exposes the quota of an user:
* <data>
* <quota>
* <free>1234</free>
* <used>4321</used>
* <total>5555</total>
* <ralative>0.78</ralative>
* </quota>
* </data>
*
* @param array $parameters should contain parameter 'userid' which identifies
* the user from whom the information will be returned
*/
public static function getUser($parameters) {
$return = array();
// Check if they are viewing information on themselves
if($parameters['userid'] === OC_User::getUser()) {
// Self lookup
$storage = OC_Helper::getStorageInfo('/');
$return['quota'] = array(
'free' => $storage['free'],
'used' => $storage['used'],
'total' => $storage['total'],
'relative' => $storage['relative'],
);
}
if(OC_User::isAdminUser(OC_User::getUser())
|| OC_Subadmin::isUserAccessible(OC_User::getUser(), $parameters['userid'])) {
if(OC_User::userExists($parameters['userid'])) {
// Is an admin/subadmin so can see display name
$return['displayname'] = OC_User::getDisplayName($parameters['userid']);
} else {
return new OC_OCS_Result(null, 101);
}
}
if(count($return)) {
return new OC_OCS_Result($return);
} else {
// No permission to view this user data
return new OC_OCS_Result(null, 997);
}
}
public static function getCurrentUser() { public static function getCurrentUser() {
$email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', ''); $email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', '');
$data = array( $data = array(

View File

@ -89,13 +89,6 @@ API::register(
'core', 'core',
API::USER_AUTH API::USER_AUTH
); );
API::register(
'get',
'/cloud/users/{userid}',
array('OC_OCS_Cloud', 'getUser'),
'core',
API::USER_AUTH
);
API::register( API::register(
'get', 'get',
'/cloud/user', '/cloud/user',