diff --git a/restapi/index.php b/restapi/index.php index 4587bee03..765355b05 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -251,7 +251,7 @@ final class SeedDMS_RestapiController { /* {{{ */ } /* }}} */ function doLogin($request, $response) { /* {{{ */ - global $session; +// global $session; $dms = $this->container->get('dms'); $settings = $this->container->get('config'); @@ -400,11 +400,11 @@ final class SeedDMS_RestapiController { /* {{{ */ $id = $args['id']; if($id == 0) { - return $this->renderer->json($response, array('success'=>true, 'message'=>'id is 0', 'data'=>''))->withStatus(200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Id is 0', 'data'=>''))->withStatus(200); } $root = $dms->getRootFolder(); if($root->getId() == $id) { - return $this->renderer->json($response, array('success'=>true, 'message'=>'id is root folder', 'data'=>''))->withStatus(200); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Id is root folder', 'data'=>''))->withStatus(200); } $folder = $dms->getFolder($id); if($folder) { @@ -1977,7 +1977,6 @@ final class SeedDMS_RestapiController { /* {{{ */ // 'creationstartdate'=>array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')), ); $resArr = $dms->search($sparams); -// $resArr = $dms->search($querystr, $limit, $offset, 'AND', $searchin, null, null, array(), array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')), array(), array(), array(), array(), array(), $objects); if($resArr === false) { return $this->renderer->json($response, array())->withStatus(200); } @@ -2279,7 +2278,8 @@ final class SeedDMS_RestapiController { /* {{{ */ return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change quota.'))->withStatus(404); } - return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); + $data = $this->__getUserData($account); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function changeUserHomefolder($request, $response, $args) { /* {{{ */ @@ -2304,23 +2304,28 @@ final class SeedDMS_RestapiController { /* {{{ */ return; } - if(!ctype_digit($args['folderid']) || $args['folderid'] == 0) { + if(!ctype_digit($args['folderid'])) { return $this->renderer->json($response, array('success'=>false, 'message'=>'No homefolder given', 'data'=>''))->withStatus(400); return; } - $newHomefolder = $dms->getFolder($args['folderid']); - if (!$newHomefolder) { - return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Folder not found.'))->withStatus(404); - return; - } + if($args['folderid'] == 0) { + $operation = $account->setHomeFolder(0); + } else { + $newHomefolder = $dms->getFolder($args['folderid']); + if (!$newHomefolder) { + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Folder not found.'))->withStatus(404); + return; + } - $operation = $account->setHomeFolder($newHomefolder->getId()); + $operation = $account->setHomeFolder($newHomefolder->getId()); + } if (!$operation){ return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change homefolder.'))->withStatus(404); } - return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); + $data = $this->__getUserData($account); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function getUserById($request, $response, $args) { /* {{{ */ @@ -2914,6 +2919,22 @@ final class SeedDMS_RestapiController { /* {{{ */ return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ + function getAttributeDefinition($request, $response, $args) { /* {{{ */ + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + + if (!ctype_digit($args['id'])) { + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); + } + + $attrdef = $dms->getAttributeDefinition($args['id']); + if ($attrdef) { + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getAttributeDefinitionData($attrdef)))->withStatus(200); + } else { + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such attributedefinition', 'data'=>''))->withStatus(404); + } + } /* }}} */ + /** * Updates the name of an existing attribute definition * @@ -3265,6 +3286,11 @@ $app->addErrorMiddleware(true, true, true); $app->add(new RestapiCorsMiddleware($container)); +/* Without the BodyParsingMiddleware the body of PUT Request will + * not be parsed in Slim4 + */ +$app->addBodyParsingMiddleware(); + // Make CORS preflighted request possible $app->options('/{routes:.+}', function ($request, $response, $args) { return $response; @@ -3347,6 +3373,7 @@ $app->delete('/categories/{id}', \SeedDMS_RestapiController::class.':deleteCateg $app->post('/categories', \SeedDMS_RestapiController::class.':createCategory'); $app->put('/categories/{id}/name', \SeedDMS_RestapiController::class.':changeCategoryName'); $app->get('/attributedefinitions', \SeedDMS_RestapiController::class.':getAttributeDefinitions'); +$app->get('/attributedefinitions/{id}', \SeedDMS_RestapiController::class.':getAttributeDefinition'); $app->put('/attributedefinitions/{id}/name', \SeedDMS_RestapiController::class.':changeAttributeDefinitionName'); $app->get('/echo/{data}', \SeedDMS_TestController::class.':echoData'); $app->get('/version', \SeedDMS_TestController::class.':version');