From b9c083e08b5429c656eedf6223302c3ec3e2b075 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:15:59 +0100 Subject: [PATCH 1/6] doLogin does not need access on global --- restapi/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restapi/index.php b/restapi/index.php index 4a6bf11f2..bf62f1064 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -241,7 +241,7 @@ final class SeedDMS_RestapiController { /* {{{ */ } /* }}} */ function doLogin($request, $response) { /* {{{ */ - global $session; +// global $session; $dms = $this->container->get('dms'); $settings = $this->container->get('config'); From 3f0275e25dce5866665cd73cece5cc41797f2c7b Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:16:27 +0100 Subject: [PATCH 2/6] fix typo in messages --- restapi/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/restapi/index.php b/restapi/index.php index bf62f1064..b99c71978 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -390,11 +390,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) { From 4e39c69224df2bd03cb568368669b3e0956dcd1b Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:17:04 +0100 Subject: [PATCH 3/6] remove old commented call of search() --- restapi/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/restapi/index.php b/restapi/index.php index b99c71978..178bcfa2d 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -1967,7 +1967,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); } From c940162328a20380ac123348c37913421f92a696 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:18:01 +0100 Subject: [PATCH 4/6] setting quota and homefolder returns the updated account --- restapi/index.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/restapi/index.php b/restapi/index.php index 178bcfa2d..75f027863 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -2264,7 +2264,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) { /* {{{ */ @@ -2289,23 +2290,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) { /* {{{ */ From 35d7d132d366c1b2948c804a58da3dc9790ddb76 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:18:58 +0100 Subject: [PATCH 5/6] add BodyParsingMiddleware because PUT request don't have access on body data --- restapi/index.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/restapi/index.php b/restapi/index.php index 75f027863..5e0d8ba61 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -3174,6 +3174,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; From 8c589a60bac7f45ee50263e1cbcf9259b81e81d2 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2025 11:19:25 +0100 Subject: [PATCH 6/6] add endpoint GET /attributedefinitions/{id} --- restapi/index.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/restapi/index.php b/restapi/index.php index 5e0d8ba61..8a59cdb58 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -2823,6 +2823,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 * @@ -3257,6 +3273,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');