2014-12-22 13:54:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-06-25 09:43:55 +00:00
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-06-25 09:43:55 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Tom Needham <tom@owncloud.com>
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* 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.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-12-22 13:54:50 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 10:44:34 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* 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/>
|
2014-12-22 13:54:50 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
namespace OCA\Provisioning_API;
|
|
|
|
|
|
|
|
use \OC_OCS_Result;
|
|
|
|
use \OC_SubAdmin;
|
|
|
|
use \OC_Helper;
|
2015-05-19 10:38:03 +00:00
|
|
|
use OCP\Files\NotFoundException;
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
class Users {
|
|
|
|
|
2015-07-25 10:46:39 +00:00
|
|
|
/** @var \OCP\IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
/** @var \OCP\IConfig */
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/** @var \OCP\IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
2015-07-25 13:01:31 +00:00
|
|
|
/** @var \OCP\IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
|
2015-07-25 10:46:39 +00:00
|
|
|
/**
|
|
|
|
* @param \OCP\IUserManager $userManager
|
2015-07-25 13:01:31 +00:00
|
|
|
* @param \OCP\IConfig $config
|
|
|
|
* @param \OCP\IGroupManager $groupManager
|
2015-09-08 12:02:30 +00:00
|
|
|
* @param \OCP\IUserSession $userSession
|
2015-07-25 10:46:39 +00:00
|
|
|
*/
|
|
|
|
public function __construct(\OCP\IUserManager $userManager,
|
2015-09-08 12:02:30 +00:00
|
|
|
\OCP\IConfig $config,
|
2015-07-25 13:01:31 +00:00
|
|
|
\OCP\IGroupManager $groupManager,
|
|
|
|
\OCP\IUserSession $userSession) {
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->groupManager = $groupManager;
|
2015-07-25 13:01:31 +00:00
|
|
|
$this->userSession = $userSession;
|
2015-07-25 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
/**
|
|
|
|
* returns a list of users
|
2015-09-08 12:02:30 +00:00
|
|
|
*
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-09-08 12:02:30 +00:00
|
|
|
public function getUsers() {
|
2014-12-22 13:54:50 +00:00
|
|
|
$search = !empty($_GET['search']) ? $_GET['search'] : '';
|
|
|
|
$limit = !empty($_GET['limit']) ? $_GET['limit'] : null;
|
|
|
|
$offset = !empty($_GET['offset']) ? $_GET['offset'] : null;
|
2015-07-25 10:46:39 +00:00
|
|
|
|
|
|
|
$users = $this->userManager->search($search, $limit, $offset);
|
|
|
|
$users = array_keys($users);
|
|
|
|
|
|
|
|
return new OC_OCS_Result([
|
|
|
|
'users' => $users
|
|
|
|
]);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 12:02:30 +00:00
|
|
|
/**
|
|
|
|
* @return OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public function addUser() {
|
2014-12-22 13:54:50 +00:00
|
|
|
$userId = isset($_POST['userid']) ? $_POST['userid'] : null;
|
|
|
|
$password = isset($_POST['password']) ? $_POST['password'] : null;
|
2015-07-25 10:46:39 +00:00
|
|
|
if($this->userManager->userExists($userId)) {
|
2015-04-09 10:36:10 +00:00
|
|
|
\OCP\Util::writeLog('ocs_api', 'Failed addUser attempt: User already exists.', \OCP\Util::ERROR);
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 102, 'User already exists');
|
|
|
|
} else {
|
|
|
|
try {
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->userManager->createUser($userId, $password);
|
2015-04-09 10:36:10 +00:00
|
|
|
\OCP\Util::writeLog('ocs_api', 'Successful addUser call with userid: '.$_POST['userid'], \OCP\Util::INFO);
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
} catch (\Exception $e) {
|
2015-04-09 10:36:10 +00:00
|
|
|
\OCP\Util::writeLog('ocs_api', 'Failed addUser attempt with exception: '.$e->getMessage(), \OCP\Util::ERROR);
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 101, 'Bad request');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gets user info
|
2015-09-08 12:02:30 +00:00
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-07-25 10:46:39 +00:00
|
|
|
public function getUser($parameters){
|
2014-12-22 13:54:50 +00:00
|
|
|
$userId = $parameters['userid'];
|
2015-08-11 13:37:06 +00:00
|
|
|
|
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
// Admin? Or SubAdmin?
|
2015-08-11 13:37:06 +00:00
|
|
|
if($this->groupManager->isAdmin($user->getUID()) || OC_SubAdmin::isUserAccessible($user->getUID(), $userId)) {
|
2014-12-22 13:54:50 +00:00
|
|
|
// Check they exist
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($userId)) {
|
2015-04-18 08:30:02 +00:00
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
// Show all
|
2015-08-11 13:37:06 +00:00
|
|
|
$return = [
|
2014-12-22 13:54:50 +00:00
|
|
|
'email',
|
|
|
|
'enabled',
|
2015-08-11 13:37:06 +00:00
|
|
|
];
|
|
|
|
if($user->getUID() !== $userId) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$return[] = 'quota';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check they are looking up themselves
|
2015-08-11 13:37:06 +00:00
|
|
|
if($user->getUID() !== $userId) {
|
2015-04-18 08:30:02 +00:00
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
// Return some additional information compared to the core route
|
|
|
|
$return = array(
|
|
|
|
'email',
|
|
|
|
'displayname',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the data
|
2015-05-19 10:38:03 +00:00
|
|
|
$data = [];
|
|
|
|
$data = self::fillStorageInfo($userId, $data);
|
2015-07-25 10:46:39 +00:00
|
|
|
$data['enabled'] = $this->config->getUserValue($userId, 'core', 'enabled', 'true');
|
|
|
|
$data['email'] = $this->config->getUserValue($userId, 'settings', 'email');
|
2015-08-11 11:01:37 +00:00
|
|
|
$data['displayname'] = $this->userManager->get($parameters['userid'])->getDisplayName();
|
2014-12-22 13:54:50 +00:00
|
|
|
|
|
|
|
// Return the appropriate data
|
|
|
|
$responseData = array();
|
|
|
|
foreach($return as $key) {
|
|
|
|
$responseData[$key] = $data[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return new OC_OCS_Result($responseData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* edit users
|
2015-09-08 12:02:30 +00:00
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-09-08 12:02:30 +00:00
|
|
|
public function editUser($parameters) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$userId = $parameters['userid'];
|
2015-08-11 13:37:06 +00:00
|
|
|
|
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($userId === $user->getUID()) {
|
2014-12-22 13:54:50 +00:00
|
|
|
// Editing self (display, email)
|
|
|
|
$permittedFields[] = 'display';
|
|
|
|
$permittedFields[] = 'email';
|
|
|
|
$permittedFields[] = 'password';
|
|
|
|
// If admin they can edit their own quota
|
2015-08-11 13:37:06 +00:00
|
|
|
if($this->groupManager->isAdmin($user->getUID())) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$permittedFields[] = 'quota';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check if admin / subadmin
|
2015-08-11 13:37:06 +00:00
|
|
|
if(OC_SubAdmin::isUserAccessible($user->getUID(), $userId)
|
|
|
|
|| $this->groupManager->isAdmin($user->getUID())) {
|
2014-12-22 13:54:50 +00:00
|
|
|
// They have permissions over the user
|
|
|
|
$permittedFields[] = 'display';
|
|
|
|
$permittedFields[] = 'quota';
|
|
|
|
$permittedFields[] = 'password';
|
|
|
|
$permittedFields[] = 'email';
|
|
|
|
} else {
|
|
|
|
// No rights
|
|
|
|
return new OC_OCS_Result(null, 997);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if permitted to edit this field
|
|
|
|
if(!in_array($parameters['_put']['key'], $permittedFields)) {
|
|
|
|
return new OC_OCS_Result(null, 997);
|
|
|
|
}
|
|
|
|
// Process the edit
|
|
|
|
switch($parameters['_put']['key']){
|
|
|
|
case 'display':
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->userManager->get($userId)->setDisplayName($parameters['_put']['value']);
|
2014-12-22 13:54:50 +00:00
|
|
|
break;
|
|
|
|
case 'quota':
|
|
|
|
$quota = $parameters['_put']['value'];
|
|
|
|
if($quota !== 'none' and $quota !== 'default') {
|
2015-05-07 15:56:13 +00:00
|
|
|
if (is_numeric($quota)) {
|
|
|
|
$quota = floatval($quota);
|
|
|
|
} else {
|
2015-08-02 08:27:36 +00:00
|
|
|
$quota = \OCP\Util::computerFileSize($quota);
|
2015-05-07 15:56:13 +00:00
|
|
|
}
|
|
|
|
if ($quota === false) {
|
|
|
|
return new OC_OCS_Result(null, 103, "Invalid quota value {$parameters['_put']['value']}");
|
|
|
|
}
|
2015-07-25 12:49:20 +00:00
|
|
|
if($quota === 0) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$quota = 'default';
|
2015-07-25 12:49:20 +00:00
|
|
|
}else if($quota === -1){
|
2014-12-22 13:54:50 +00:00
|
|
|
$quota = 'none';
|
|
|
|
} else {
|
2015-08-02 08:27:36 +00:00
|
|
|
$quota = \OCP\Util::humanFileSize($quota);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->config->setUserValue($userId, 'files', 'quota', $quota);
|
2014-12-22 13:54:50 +00:00
|
|
|
break;
|
|
|
|
case 'password':
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->userManager->get($userId)->setPassword($parameters['_put']['value']);
|
2014-12-22 13:54:50 +00:00
|
|
|
break;
|
|
|
|
case 'email':
|
|
|
|
if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) {
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->config->setUserValue($userId, 'settings', 'email', $parameters['_put']['value']);
|
2014-12-22 13:54:50 +00:00
|
|
|
} else {
|
|
|
|
return new OC_OCS_Result(null, 102);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new OC_OCS_Result(null, 103);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
}
|
|
|
|
|
2015-09-08 12:02:30 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public function deleteUser($parameters) {
|
2015-08-11 13:37:06 +00:00
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($parameters['userid'])
|
2015-08-11 13:37:06 +00:00
|
|
|
|| $parameters['userid'] === $user->getUID()) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 101);
|
|
|
|
}
|
|
|
|
// If not permitted
|
2015-08-11 13:37:06 +00:00
|
|
|
if(!$this->groupManager->isAdmin($user->getUID()) && !OC_SubAdmin::isUserAccessible($user->getUID(), $parameters['userid'])) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 997);
|
|
|
|
}
|
|
|
|
// Go ahead with the delete
|
2015-07-25 10:46:39 +00:00
|
|
|
if($this->userManager->get($parameters['userid'])->delete()) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
} else {
|
|
|
|
return new OC_OCS_Result(null, 101);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 12:02:30 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
|
|
|
*/
|
2015-08-11 13:37:06 +00:00
|
|
|
public function getUsersGroups($parameters) {
|
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($parameters['userid'] === $user->getUID() || $this->groupManager->isAdmin($user->getUID())) {
|
2014-12-22 13:54:50 +00:00
|
|
|
// Self lookup or admin lookup
|
2015-07-25 10:46:39 +00:00
|
|
|
return new OC_OCS_Result([
|
|
|
|
'groups' => $this->groupManager->getUserGroupIds(
|
|
|
|
$this->userManager->get($parameters['userid'])
|
|
|
|
)
|
|
|
|
]);
|
2014-12-22 13:54:50 +00:00
|
|
|
} else {
|
|
|
|
// Looking up someone else
|
2015-08-11 13:37:06 +00:00
|
|
|
if(OC_SubAdmin::isUserAccessible($user->getUID(), $parameters['userid'])) {
|
2014-12-22 13:54:50 +00:00
|
|
|
// Return the group that the method caller is subadmin of for the user in question
|
2015-07-25 10:46:39 +00:00
|
|
|
$groups = array_intersect(
|
2015-08-11 13:37:06 +00:00
|
|
|
OC_SubAdmin::getSubAdminsGroups($user->getUID()),
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->groupManager->getUserGroupIds(
|
|
|
|
$this->userManager->get($parameters['userid'])
|
|
|
|
)
|
|
|
|
);
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(array('groups' => $groups));
|
|
|
|
} else {
|
|
|
|
// Not permitted
|
|
|
|
return new OC_OCS_Result(null, 997);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-08 12:02:30 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public function addToGroup($parameters) {
|
2015-08-11 13:37:06 +00:00
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
$group = !empty($_POST['groupid']) ? $_POST['groupid'] : null;
|
|
|
|
if(is_null($group)){
|
|
|
|
return new OC_OCS_Result(null, 101);
|
|
|
|
}
|
|
|
|
// Check they're an admin
|
2015-08-11 13:37:06 +00:00
|
|
|
if(!$this->groupManager->isInGroup($user->getUID(), 'admin')){
|
2014-12-22 13:54:50 +00:00
|
|
|
// This user doesn't have rights to add a user to this group
|
2015-04-18 08:30:02 +00:00
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
// Check if the group exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->groupManager->groupExists($group)){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 102);
|
|
|
|
}
|
|
|
|
// Check if the user exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($parameters['userid'])){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 103);
|
|
|
|
}
|
|
|
|
// Add user to group
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->groupManager->get($group)->addUser(
|
|
|
|
$this->userManager->get($parameters['userid'])
|
|
|
|
);
|
|
|
|
return new OC_OCS_Result(null, 100);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 12:02:30 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
|
|
|
*/
|
2015-08-11 13:37:06 +00:00
|
|
|
public function removeFromGroup($parameters) {
|
|
|
|
// Check if user is logged in
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user === null) {
|
|
|
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
|
|
|
}
|
|
|
|
|
2014-12-22 13:54:50 +00:00
|
|
|
$group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null;
|
|
|
|
if(is_null($group)){
|
|
|
|
return new OC_OCS_Result(null, 101);
|
|
|
|
}
|
|
|
|
// If they're not an admin, check they are a subadmin of the group in question
|
2015-08-11 13:37:06 +00:00
|
|
|
if(!$this->groupManager->isInGroup($user->getUID(), 'admin') && !OC_SubAdmin::isSubAdminofGroup($user->getUID(), $group)){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 104);
|
|
|
|
}
|
|
|
|
// Check they aren't removing themselves from 'admin' or their 'subadmin; group
|
2015-08-11 13:37:06 +00:00
|
|
|
if($parameters['userid'] === $user->getUID()){
|
|
|
|
if($this->groupManager->isInGroup($user->getUID(), 'admin')){
|
2014-12-22 13:54:50 +00:00
|
|
|
if($group === 'admin'){
|
|
|
|
return new OC_OCS_Result(null, 105, 'Cannot remove yourself from the admin group');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Not an admin, check they are not removing themself from their subadmin group
|
2015-08-11 13:37:06 +00:00
|
|
|
if(in_array($group, OC_SubAdmin::getSubAdminsGroups($user->getUID()))){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if the group exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->groupManager->groupExists($group)){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 102);
|
|
|
|
}
|
|
|
|
// Check if the user exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($parameters['userid'])){
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 103);
|
|
|
|
}
|
|
|
|
// Remove user from group
|
2015-07-25 10:46:39 +00:00
|
|
|
$this->groupManager->get($group)->removeUser(
|
|
|
|
$this->userManager->get($parameters['userid'])
|
|
|
|
);
|
|
|
|
return new OC_OCS_Result(null, 100);
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a subadmin
|
2015-09-08 12:02:30 +00:00
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-07-25 10:46:39 +00:00
|
|
|
public function addSubAdmin($parameters) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$group = $_POST['groupid'];
|
|
|
|
$user = $parameters['userid'];
|
|
|
|
// Check if the user exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($user)) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 101, 'User does not exist');
|
|
|
|
}
|
|
|
|
// Check if group exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->groupManager->groupExists($group)) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 102, 'Group:'.$group.' does not exist');
|
|
|
|
}
|
|
|
|
// Check if trying to make subadmin of admin group
|
2015-07-25 12:49:20 +00:00
|
|
|
if(strtolower($group) === 'admin') {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 103, 'Cannot create subadmins for admin group');
|
|
|
|
}
|
2015-04-13 08:32:18 +00:00
|
|
|
// We cannot be subadmin twice
|
|
|
|
if (OC_Subadmin::isSubAdminOfGroup($user, $group)) {
|
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
}
|
2014-12-22 13:54:50 +00:00
|
|
|
// Go
|
|
|
|
if(OC_Subadmin::createSubAdmin($user, $group)) {
|
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
} else {
|
|
|
|
return new OC_OCS_Result(null, 103, 'Unknown error occured');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a subadmin from a group
|
2015-09-08 12:02:30 +00:00
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-07-25 10:46:39 +00:00
|
|
|
public function removeSubAdmin($parameters) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$group = $parameters['_delete']['groupid'];
|
|
|
|
$user = $parameters['userid'];
|
|
|
|
// Check if the user exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($user)) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 101, 'User does not exist');
|
|
|
|
}
|
|
|
|
// Check if they are a subadmin of this said group
|
|
|
|
if(!OC_SubAdmin::isSubAdminofGroup($user, $group)) {
|
|
|
|
return new OC_OCS_Result(null, 102, 'User is not a subadmin of this group');
|
|
|
|
}
|
|
|
|
// Go
|
|
|
|
if(OC_Subadmin::deleteSubAdmin($user, $group)) {
|
|
|
|
return new OC_OCS_Result(null, 100);
|
|
|
|
} else {
|
|
|
|
return new OC_OCS_Result(null, 103, 'Unknown error occurred');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-08 12:02:30 +00:00
|
|
|
* Get the groups a user is a subadmin of
|
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @return OC_OCS_Result
|
2014-12-22 13:54:50 +00:00
|
|
|
*/
|
2015-07-25 10:46:39 +00:00
|
|
|
public function getUserSubAdminGroups($parameters) {
|
2014-12-22 13:54:50 +00:00
|
|
|
$user = $parameters['userid'];
|
|
|
|
// Check if the user exists
|
2015-07-25 10:46:39 +00:00
|
|
|
if(!$this->userManager->userExists($user)) {
|
2014-12-22 13:54:50 +00:00
|
|
|
return new OC_OCS_Result(null, 101, 'User does not exist');
|
|
|
|
}
|
|
|
|
// Get the subadmin groups
|
|
|
|
if(!$groups = OC_SubAdmin::getSubAdminsGroups($user)) {
|
|
|
|
return new OC_OCS_Result(null, 102, 'Unknown error occurred');
|
|
|
|
} else {
|
|
|
|
return new OC_OCS_Result($groups);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 10:38:03 +00:00
|
|
|
|
|
|
|
/**
|
2015-09-08 12:02:30 +00:00
|
|
|
* @param string $userId
|
|
|
|
* @param array $data
|
2015-05-19 10:38:03 +00:00
|
|
|
* @return mixed
|
|
|
|
* @throws \OCP\Files\NotFoundException
|
|
|
|
*/
|
|
|
|
private static function fillStorageInfo($userId, $data) {
|
|
|
|
try {
|
|
|
|
\OC_Util::tearDownFS();
|
|
|
|
\OC_Util::setupFS($userId);
|
|
|
|
$storage = OC_Helper::getStorageInfo('/');
|
|
|
|
$data['quota'] = [
|
|
|
|
'free' => $storage['free'],
|
|
|
|
'used' => $storage['used'],
|
|
|
|
'total' => $storage['total'],
|
|
|
|
'relative' => $storage['relative'],
|
|
|
|
];
|
|
|
|
} catch (NotFoundException $ex) {
|
|
|
|
$data['quota'] = [];
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2014-12-22 13:54:50 +00:00
|
|
|
}
|