diff --git a/restapi/index.php b/restapi/index.php index 2548d737c..f62aba596 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -2194,6 +2194,92 @@ class RestapiController { /* {{{ */ return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); } /* }}} */ + /** + * Updates the quota of an existing account + * + * @param $id The user name or numerical identifier + */ + function changeUserQuota($request, $response, $args) { /* {{{ */ + $dms = $this->container->dms; + $userobj = $this->container->userobj; + + $check = $this->checkIfAdmin($request, $response); + if($check !== true) + return $check; + + $params = $request->getParsedBody(); + if ($params['quota'] == null) { + return $response->withJson(array('success'=>false, 'message'=>'You must supply a new quota', 'data'=>''), 400); + } + + $newQuota = $params['quota']; + + if(ctype_digit($args['id'])) + $account = $dms->getUser($args['id']); + else { + $account = $dms->getUserByLogin($args['id']); + } + + /** + * User not found + */ + if (!$account) { + return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'User not found.'), 404); + return; + } + + $operation = $account->setQuota($newQuota); + + if (!$operation){ + return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change quota.'), 404); + } + + return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + } /* }}} */ + + function changeUserHomefolder($request, $response, $args) { /* {{{ */ + $dms = $this->container->dms; + $userobj = $this->container->userobj; + + $check = $this->checkIfAdmin($request, $response); + if($check !== true) + return $check; + + $params = $request->getParsedBody(); + if ($params['homefolder'] == null) { + return $response->withJson(array('success'=>false, 'message'=>'You must supply a new home folder', 'data'=>''), 400); + } + + $newHomefolderId = (int) $params['homefolder']; + $newHomefolder = $dms->getFolder($newHomefolderId); + if (!$newHomefolder) { + return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Folder not found.'), 404); + return; + } + + if(ctype_digit($args['id'])) + $account = $dms->getUser($args['id']); + else { + $account = $dms->getUserByLogin($args['id']); + } + + /** + * User not found + */ + if (!$account) { + return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'User not found.'), 404); + return; + } + + $operation = $account->setHomeFolder($newHomefolder->getId()); + + if (!$operation){ + return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change homefolder.'), 404); + } + + return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + } /* }}} */ + function getUserById($request, $response, $args) { /* {{{ */ $dms = $this->container->dms; $userobj = $this->container->userobj; @@ -2435,6 +2521,46 @@ class RestapiController { /* {{{ */ } } /* }}} */ + function setFolderOwner($request, $response, $args) { /* {{{ */ + $dms = $this->container->dms; + $userobj = $this->container->userobj; + + if(!$userobj) { + return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + } + if(!$userobj->isAdmin()) { + return $response->withJson(array('success'=>false, 'message'=>'No access on folder', 'data'=>''), 403); + } + + if(!ctype_digit($args['id']) || $args['id'] == 0) { + return $response->withJson(array('success'=>false, 'message'=>'No folder given', 'data'=>''), 400); + return; + } + if(!ctype_digit($args['userid']) || $args['userid'] == 0) { + return $response->withJson(array('success'=>false, 'message'=>'No user given', 'data'=>''), 400); + return; + } + $owner = $dms->getUser($args['userid']); + $folder = $dms->getFolder($args['id']); + if($folder && $owner) { + if($folder->getAccessMode($userobj, 'setDocumentOwner') > M_READ) { + if ($folder->setOwner($owner)){ + return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + } else { + return $response->withJson(array('success'=>false, 'message'=>'Could not set owner of folder', 'data'=>''), 500); + } + } else { + return $response->withJson(array('success'=>false, 'message'=>'No access on folder', 'data'=>''), 403); + } + } else { + if(!$doc) + return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + if(!$owner) + return $response->withJson(array('success'=>false, 'message'=>'No such user', 'data'=>''), 404); + return $response->withJson(array('success'=>false, 'message'=>'Could not find user or folder', 'data'=>''), 500); + } + } /* }}} */ + function addUserAccessToFolder($request, $response, $args) { /* {{{ */ return $this->changeFolderAccess($request, $response, $args, 'add', 'user'); } /* }}} */ @@ -2972,6 +3098,8 @@ $app->post('/users', \RestapiController::class.':createUser'); $app->get('/users/{id}', \RestapiController::class.':getUserById'); $app->put('/users/{id}/disable', \RestapiController::class.':setDisabledUser'); $app->put('/users/{id}/password', \RestapiController::class.':changeUserPassword'); +$app->put('/users/{id}/quota', \RestapiController::class.':changeUserQuota'); +$app->put('/users/{id}/homefolder', \RestapiController::class.':changeUserHomefolder'); $app->post('/groups', \RestapiController::class.':createGroup'); $app->get('/groups', \RestapiController::class.':getGroups'); $app->delete('/groups/{id}', \RestapiController::class.':deleteGroup'); @@ -2979,6 +3107,7 @@ $app->get('/groups/{id}', \RestapiController::class.':getGroup'); $app->put('/groups/{id}/addUser', \RestapiController::class.':addUserToGroup'); $app->put('/groups/{id}/removeUser', \RestapiController::class.':removeUserFromGroup'); $app->put('/folder/{id}/setInherit', \RestapiController::class.':setFolderInheritsAccess'); +$app->put('/folder/{id}/owner/{userid}', \RestapiController::class.':setFolderOwner'); $app->put('/folder/{id}/access/group/add', \RestapiController::class.':addGroupAccessToFolder'); // $app->put('/folder/{id}/access/user/add', \RestapiController::class.':addUserAccessToFolder'); // $app->put('/folder/{id}/access/group/remove', \RestapiController::class.':removeGroupAccessFromFolder');