diff --git a/composer-dist.json b/composer-dist.json index 93c4e2203..a5b830e5e 100644 --- a/composer-dist.json +++ b/composer-dist.json @@ -8,7 +8,7 @@ "robthree/twofactorauth": "^1.5", "sabre/dav": "^4.", "sabre/xml": "*", - "slim/slim": "^3.0", + "slim/slim": "^4.0", "erusev/parsedown": "*", "erusev/parsedown-extra": "*", "pear/log": "*", @@ -20,6 +20,7 @@ "alecrabbit/php-console-colour": "*", "zf1/zend-search-lucene": "*", "symfony/http-foundation": "^5.4", + "php-di/php-di": "^6.4", "seeddms/core": "dev-master", "seeddms/lucene": "dev-master", "seeddms/preview": "dev-master", @@ -66,5 +67,4 @@ } } ] - } diff --git a/inc/inc.ClassAuthenticationMiddleware.php b/inc/inc.ClassAuthenticationMiddleware.php index fa8d0fdc7..97e74c55f 100644 --- a/inc/inc.ClassAuthenticationMiddleware.php +++ b/inc/inc.ClassAuthenticationMiddleware.php @@ -48,18 +48,18 @@ class SeedDMS_Auth_Middleware_Session { /* {{{ */ * * @return \Psr\Http\Message\ResponseInterface */ - public function __invoke($request, $response, $next) { + public function __invoke($request, $handler) { // $this->container has the DI - $dms = $this->container->dms; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); $userobj = null; if ($this->container->has('userobj')) { - $userobj = $this->container->userobj; + $userobj = $this->container->get('userobj'); } if ($userobj) { - $response = $next($request, $response); + $response = $handler->handle($request); return $response; } @@ -100,9 +100,9 @@ class SeedDMS_Auth_Middleware_Session { /* {{{ */ } else { return $response->withStatus(403); } - $this->container['userobj'] = $userobj; + $this->container->set('userobj', $userobj); - $response = $next($request, $response); + $response = $handler->handle($request); return $response; } } /* }}} */ diff --git a/index.php b/index.php index b6fa64a0d..bf780ef9a 100644 --- a/index.php +++ b/index.php @@ -31,6 +31,9 @@ require "inc/inc.Settings.php"; +use DI\ContainerBuilder; +use Slim\Factory\AppFactory; + if(true) { require_once("inc/inc.Utils.php"); require_once("inc/inc.LogInit.php"); @@ -39,7 +42,9 @@ if(true) { require_once("inc/inc.Extension.php"); require_once("inc/inc.DBInit.php"); - $c = new \Slim\Container(); //Create Your container + $containerBuilder = new \DI\ContainerBuilder(); + $c = $containerBuilder->build(); + /* $c['notFoundHandler'] = function ($c) use ($settings, $dms) { return function ($request, $response) use ($c, $settings, $dms) { $uri = $request->getUri(); @@ -62,25 +67,42 @@ if(true) { ->withHeader('Location', isset($settings->_siteDefaultPage) && strlen($settings->_siteDefaultPage)>0 ? $settings->_httpRoot.$settings->_siteDefaultPage : $settings->_httpRoot."out/out.ViewFolder.php"); }; }; - $app = new \Slim\App($c); + */ + AppFactory::setContainer($c); + $app = AppFactory::create(); + /* put lots of data into the container, because if slim instanciates + * a class by itself (with the help from the DI container), it will + * pass the container to the constructor of the instanciated class. + */ $container = $app->getContainer(); - $container['dms'] = $dms; - $container['config'] = $settings; - $container['conversionmgr'] = $conversionmgr; - $container['logger'] = $logger; - $container['fulltextservice'] = $fulltextservice; - $container['notifier'] = $notifier; - $container['authenticator'] = $authenticator; + $container->set('dms', $dms); + $container->set('config', $settings); + $container->set('conversionmgr', $conversionmgr); + $container->set('logger', $logger); + $container->set('fulltextservice', $fulltextservice); + $container->set('notifier', $notifier); + $container->set('authenticator', $authenticator); + if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) { + foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) { + if (method_exists($hookObj, 'addMiddleware')) { + $hookObj->addMiddleware($app); + } + } + } + + $app->get('/', function($request, $response) { + return $response + ->withHeader('Location', '/out/out.ViewFolder.php') + ->withStatus(302); + + }); if(isset($GLOBALS['SEEDDMS_HOOKS']['initDMS'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) { if (method_exists($hookObj, 'addRoute')) { + // FIXME: pass $app only just like initRestAPI. $app has a container + // which contains all other objects $hookObj->addRoute(array('dms'=>$dms, 'app'=>$app, 'settings'=>$settings, 'conversionmgr'=>$conversionmgr, 'authenticator'=>$authenticator, 'fulltextservice'=>$fulltextservice, 'logger'=>$logger)); -// } else { -// include("inc/inc.Authentication.php"); -// if (method_exists($hookObj, 'addRouteAfterAuthentication')) { -// $hookObj->addRouteAfterAuthentication(array('dms'=>$dms, 'app'=>$app, 'settings'=>$settings, 'user'=>$user)); -// } } } } diff --git a/restapi/index.php b/restapi/index.php index 55260ae0b..c5d92c03e 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -18,13 +18,40 @@ require_once("../inc/inc.ClassController.php"); require "vendor/autoload.php"; use Psr\Container\ContainerInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; +use Psr\Http\Server\MiddlewareInterface; +use DI\ContainerBuilder; +use Slim\Factory\AppFactory; -class RestapiController { /* {{{ */ +final class JsonRenderer +{ + public function json( + ResponseInterface $response, + array $data = null + ): ResponseInterface { + $response = $response->withHeader('Content-Type', 'application/json'); + + $response->getBody()->write( + (string)json_encode( + $data, + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + + return $response; + } +} + +final class SeedDMS_RestapiController { /* {{{ */ protected $container; + protected $renderer; - // constructor receives container instance - public function __construct(ContainerInterface $container) { + // constructor receives container and renderer instance by DI + public function __construct(ContainerInterface $container, JsonRenderer $renderer) { $this->container = $container; + $this->renderer = $renderer; } protected function __getAttributesData($obj) { /* {{{ */ @@ -219,15 +246,15 @@ class RestapiController { /* {{{ */ function doLogin($request, $response) { /* {{{ */ global $session; - $dms = $this->container->dms; - $settings = $this->container->config; - $logger = $this->container->logger; - $authenticator = $this->container->authenticator; + $dms = $this->container->get('dms'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + $authenticator = $this->container->get('authenticator'); $params = $request->getParsedBody(); if(empty($params['user']) || empty($params['pass'])) { $logger->log("Login without username or password failed", PEAR_LOG_INFO); - return $response->withJson(array('success'=>false, 'message'=>'No user or password given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No user or password given', 'data'=>''))->withStatus(400); } $username = $params['user']; $password = $params['pass']; @@ -236,12 +263,12 @@ class RestapiController { /* {{{ */ if(!$userobj) { setcookie("mydms_session", '', time()-3600, $settings->_httpRoot); $logger->log("Login with user name '".$username."' failed", PEAR_LOG_ERR); - return $response->withJson(array('success'=>false, 'message'=>'Login failed', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Login failed', 'data'=>''))->withStatus(403); } else { require_once("../inc/inc.ClassSession.php"); $session = new SeedDMS_Session($dms->getDb()); if(!$id = $session->create(array('userid'=>$userobj->getId(), 'theme'=>$userobj->getTheme(), 'lang'=>$userobj->getLanguage()))) { - return $response->withJson(array('success'=>false, 'message'=>'Creating session failed', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Creating session failed', 'data'=>''))->withStatus(500); } // Set the session cookie. @@ -253,14 +280,14 @@ class RestapiController { /* {{{ */ $dms->setUser($userobj); $logger->log("Login with user name '".$username."' successful", PEAR_LOG_INFO); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getUserData($userobj)), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getUserData($userobj)))->withStatus(200); } } /* }}} */ function doLogout($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); if(isset($_COOKIE['mydms_session'])) { $dms_session = $_COOKIE["mydms_session"]; @@ -280,42 +307,42 @@ class RestapiController { /* {{{ */ } setcookie("mydms_session", '', time()-3600, $settings->_httpRoot); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } /* }}} */ function setFullName($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); return; } $params = $request->getParsedBody(); $userobj->setFullName($params['fullname']); $data = $this->__getUserData($userobj); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function setEmail($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); return; } $params = $request->getParsedBody(); $userobj->setEmail($params['email']); $data = $this->__getUserData($userobj); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function getLockedDocuments($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(false !== ($documents = $dms->getDocumentsLockedByUser($userobj))) { $documents = SeedDMS_Core_DMS::filterAccess($documents, $userobj, M_READ); @@ -326,16 +353,16 @@ class RestapiController { /* {{{ */ $recs[] = $this->__getLatestVersionData($lc); } } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } } /* }}} */ function getFolder($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); $params = $request->getQueryParams(); $forcebyname = isset($params['forcebyname']) ? $params['forcebyname'] : 0; @@ -351,26 +378,26 @@ class RestapiController { /* {{{ */ if($folder) { if($folder->getAccessMode($userobj) >= M_READ) { $data = $this->__getFolderData($folder); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } /* }}} */ function getFolderParent($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $id = $args['id']; if($id == 0) { - return $response->withJson(array('success'=>true, 'message'=>'id is 0', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'id is 0', 'data'=>''))->withStatus(200); } $root = $dms->getRootFolder(); if($root->getId() == $id) { - return $response->withJson(array('success'=>true, 'message'=>'id is root folder', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'id is root folder', 'data'=>''))->withStatus(200); } $folder = $dms->getFolder($id); if($folder) { @@ -378,24 +405,24 @@ class RestapiController { /* {{{ */ if($parent) { if($parent->getAccessMode($userobj) >= M_READ) { $rec = $this->__getFolderData($parent); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$rec), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$rec))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } /* }}} */ function getFolderPath($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(empty($args['id'])) { - return $response->withJson(array('success'=>true, 'message'=>'id is 0', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'id is 0', 'data'=>''))->withStatus(200); } $folder = $dms->getFolder($args['id']); if($folder) { @@ -405,40 +432,40 @@ class RestapiController { /* {{{ */ foreach($path as $element) { $data[] = array('id'=>$element->getId(), 'name'=>$element->getName()); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } /* }}} */ function getFolderAttributes($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $folder = $dms->getFolder($args['id']); if($folder) { if ($folder->getAccessMode($userobj) >= M_READ) { $attributes = $this->__getAttributesData($folder); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$attributes), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$attributes))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } /* }}} */ function getFolderChildren($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(empty($args['id'])) { $folder = $dms->getRootFolder(); $recs = array($this->$this->__getFolderData($folder)); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { $folder = $dms->getFolder($args['id']); if($folder) { @@ -457,30 +484,30 @@ class RestapiController { /* {{{ */ $recs[] = $this->__getLatestVersionData($lc); } } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } } /* }}} */ function createFolder($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); + $notifier = $this->container->get('notifier'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No parent folder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No parent folder given', 'data'=>''))->withStatus(400); return; } $parent = $dms->getFolder($args['id']); @@ -492,7 +519,7 @@ class RestapiController { /* {{{ */ if(isset($params['sequence'])) { $sequence = str_replace(',', '.', $params["sequence"]); if (!is_numeric($sequence)) - return $response->withJson(array('success'=>false, 'message'=>getMLText("invalid_sequence"), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("invalid_sequence"), 'data'=>''))->withStatus(400); } else { $dd = $parent->getSubFolders('s'); if(count($dd) > 1) @@ -515,7 +542,7 @@ class RestapiController { /* {{{ */ /* Check if name already exists in the folder */ if(!$settings->_enableDuplicateSubFolderNames) { if($parent->hasSubFolderByName($params['name'])) { - return $response->withJson(array('success'=>false, 'message'=>getMLText("subfolder_duplicate_name"), 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("subfolder_duplicate_name"), 'data'=>''))->withStatus(409); } } @@ -536,35 +563,35 @@ class RestapiController { /* {{{ */ if($notifier) { $notifier->sendNewFolderMail($folder, $userobj); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$rec), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$rec))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not create folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not create folder', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'Missing folder name', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Missing folder name', 'data'=>''))->withStatus(400); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not find parent folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find parent folder', 'data'=>''))->withStatus(404); } } /* }}} */ function moveFolder($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No source folder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No source folder given', 'data'=>''))->withStatus(400); } if(!ctype_digit($args['folderid']) || $args['folderid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No destination folder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No destination folder given', 'data'=>''))->withStatus(400); } $mfolder = $dms->getFolder($args['id']); @@ -573,82 +600,82 @@ class RestapiController { /* {{{ */ if($folder = $dms->getFolder($args['folderid'])) { if($folder->getAccessMode($userobj, 'moveFolder') >= M_READWRITE) { if($mfolder->setParent($folder)) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Error moving folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Error moving folder', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''))->withStatus(403); } } else { if($folder === null) $status = 404; else $status = 500; - return $response->withJson(array('success'=>false, 'message'=>'No destination folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No destination folder', 'data'=>''))->withStatus($status); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($mfolder === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder', 'data'=>''))->withStatus($status); } } /* }}} */ function deleteFolder($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'id is 0', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'id is 0', 'data'=>''))->withStatus(400); } $mfolder = $dms->getFolder($args['id']); if($mfolder) { if ($mfolder->getAccessMode($userobj, 'removeFolder') >= M_READWRITE) { if($mfolder->remove()) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Error deleting folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Error deleting folder', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($mfolder === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder', 'data'=>''))->withStatus($status); } } /* }}} */ function uploadDocument($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $notifier = $this->container->notifier; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $notifier = $this->container->get('notifier'); + $fulltextservice = $this->container->get('fulltextservice'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No parent folder id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No parent folder id given', 'data'=>''))->withStatus(400); } if($settings->_quota > 0) { $remain = checkQuota($userobj); if ($remain < 0) { - return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''))->withStatus(400); } } @@ -663,7 +690,7 @@ class RestapiController { /* {{{ */ if(isset($params['sequence'])) { $sequence = str_replace(',', '.', $params["sequence"]); if (!is_numeric($sequence)) - return $response->withJson(array('success'=>false, 'message'=>getMLText("invalid_sequence"), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("invalid_sequence"), 'data'=>''))->withStatus(400); } else { $dd = $mfolder->getDocuments('s'); if(count($dd) > 1) @@ -674,7 +701,7 @@ class RestapiController { /* {{{ */ if(isset($params['expdate'])) { $tmp = explode('-', $params["expdate"]); if(count($tmp) != 3) - return $response->withJson(array('success'=>false, 'message'=>getMLText('malformed_expiration_date'), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText('malformed_expiration_date'), 'data'=>''))->withStatus(400); $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]); } else $expires = 0; @@ -700,15 +727,15 @@ class RestapiController { /* {{{ */ if($attrdef) { if($attribute) { if(!$attrdef->validate($attribute)) { - return $response->withJson(array('success'=>false, 'message'=>getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute), 'data'=>''))->withStatus(400); } } elseif($attrdef->getMinValues() > 0) { - return $response->withJson(array('success'=>false, 'message'=>getMLText("attr_min_values", array("attrname"=>$attrdef->getName())), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("attr_min_values", array("attrname"=>$attrdef->getName())), 'data'=>''))->withStatus(400); } } } if (count($uploadedFiles) == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No file detected', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No file detected', 'data'=>''))->withStatus(400); } $file_info = array_pop($uploadedFiles); if ($origfilename == null) @@ -718,7 +745,7 @@ class RestapiController { /* {{{ */ /* Check if name already exists in the folder */ if(!$settings->_enableDuplicateDocNames) { if($mfolder->hasDocumentByName($docname)) { - return $response->withJson(array('success'=>false, 'message'=>getMLText("document_duplicate_name"), 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("document_duplicate_name"), 'data'=>''))->withStatus(409); } } // Get the list of reviewers and approvers for this document. @@ -796,7 +823,7 @@ class RestapiController { /* {{{ */ $errmsg = $err; } unlink($temp); - return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Upload failed', 'data'=>''))->withStatus(500); } else { if($controller->hasHook('cleanUpDocument')) { $controller->callHook('cleanUpDocument', $document, ['Ń•ource'=>'restapi', 'type'=>$userfiletype, 'name'=>$origfilename]); @@ -806,7 +833,7 @@ class RestapiController { /* {{{ */ $notifier->sendNewDocumentMail($document, $userobj); } unlink($temp); - return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$this->__getLatestVersionData($document->getLatestContent())), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Upload succeded', 'data'=>$this->__getLatestVersionData($document->getLatestContent())))->withStatus(201); } /* $res = $mfolder->addDocument($docname, $comment, $expires, $owner ? $owner : $userobj, $keywords, $cats, $temp, $origfilename ? $origfilename : basename($temp), $fileType, $userfiletype, $sequence, array(), array(), $reqversion, $version_comment, $attributes); @@ -816,49 +843,49 @@ class RestapiController { /* {{{ */ if($notifier) { $notifier->sendNewDocumentMail($doc, $userobj); } - return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$this->__getLatestVersionData($doc->getLatestContent())), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Upload succeded', 'data'=>$this->__getLatestVersionData($doc->getLatestContent())))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Upload failed', 'data'=>''))->withStatus(500); } */ } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($mfolder === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder', 'data'=>''))->withStatus($status); } } /* }}} */ function updateDocument($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $notifier = $this->container->notifier; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $notifier = $this->container->get('notifier'); + $fulltextservice = $this->container->get('fulltextservice'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document id given', 'data'=>''))->withStatus(400); } if($settings->_quota > 0) { $remain = checkQuota($userobj); if ($remain < 0) { - return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''))->withStatus(400); } } $document = $dms->getDocument($args['id']); if($document) { if ($document->getAccessMode($userobj, 'updateDocument') < M_READWRITE) { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } $params = $request->getParsedBody(); @@ -873,16 +900,16 @@ class RestapiController { /* {{{ */ if($attrdef) { if($attribute) { if(!$attrdef->validate($attribute)) { - return $response->withJson(array('success'=>false, 'message'=>getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute), 'data'=>''))->withStatus(400); } } elseif($attrdef->getMinValues() > 0) { - return $response->withJson(array('success'=>false, 'message'=>getMLText("attr_min_values", array("attrname"=>$attrdef->getName())), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("attr_min_values", array("attrname"=>$attrdef->getName())), 'data'=>''))->withStatus(400); } } } $uploadedFiles = $request->getUploadedFiles(); if (count($uploadedFiles) == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No file detected', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No file detected', 'data'=>''))->withStatus(400); } $file_info = array_pop($uploadedFiles); if ($origfilename == null) @@ -892,13 +919,13 @@ class RestapiController { /* {{{ */ /* Check if the uploaded file is identical to last version */ $lc = $document->getLatestContent(); if($lc->getChecksum() == SeedDMS_Core_File::checksum($temp)) { - return $response->withJson(array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''))->withStatus(400); } if($document->isLocked()) { $lockingUser = $document->getLockingUser(); if(($lockingUser->getID() != $userobj->getID()) && ($document->getAccessMode($userobj) != M_ALL)) { - return $response->withJson(array('success'=>false, 'message'=>'Document is locked', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Document is locked', 'data'=>''))->withStatus(400); } else $document->setLocked(false); } @@ -967,7 +994,7 @@ class RestapiController { /* {{{ */ } else { $errmsg = $err; } - return $response->withJson(array('success'=>false, 'message'=>'Upload failed: '.$errmsg, 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Upload failed: '.$errmsg, 'data'=>''))->withStatus(500); } else { unlink($temp); if($controller->hasHook('cleanUpDocument')) { @@ -981,10 +1008,10 @@ class RestapiController { /* {{{ */ } $rec = array('id'=>(int)$document->getId(), 'name'=>$document->getName(), 'version'=>$document->getLatestContent()->getVersion()); - return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec))->withStatus(200); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus(404); } } /* }}} */ @@ -992,23 +1019,23 @@ class RestapiController { /* {{{ */ * Old upload method which uses put instead of post */ function uploadDocumentPut($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $notifier = $this->container->get('notifier'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document id given', 'data'=>''))->withStatus(400); } if($settings->_quota > 0) { $remain = checkQuota($userobj); if ($remain < 0) { - return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''))->withStatus(400); } } @@ -1031,7 +1058,7 @@ class RestapiController { /* {{{ */ /* Check if name already exists in the folder */ if(!$settings->_enableDuplicateDocNames) { if($mfolder->hasDocumentByName($docname)) { - return $response->withJson(array('success'=>false, 'message'=>getMLText("document_duplicate_name"), 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>getMLText("document_duplicate_name"), 'data'=>''))->withStatus(409); } } $res = $mfolder->addDocument($docname, '', 0, $userobj, '', array(), $temp, $origfilename ? $origfilename : basename($temp), $fileType, $userfiletype, 0); @@ -1042,32 +1069,32 @@ class RestapiController { /* {{{ */ $notifier->sendNewDocumentMail($doc, $userobj); } $rec = array('id'=>(int)$doc->getId(), 'name'=>$doc->getName()); - return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Upload failed', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($mfolder === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder', 'data'=>''))->withStatus($status); } } /* }}} */ function uploadDocumentFile($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document id given', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); if($document) { @@ -1081,7 +1108,7 @@ class RestapiController { /* {{{ */ $version = empty($params['version']) ? 0 : $params['version']; $public = empty($params['public']) ? 'false' : $params['public']; if (count($uploadedFiles) == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No file detected', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No file detected', 'data'=>''))->withStatus(400); } $file_info = array_pop($uploadedFiles); if ($origfilename == null) @@ -1098,36 +1125,36 @@ class RestapiController { /* {{{ */ $fileType, $userfiletype, $version, $public); unlink($temp); if($res) { - return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$res), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Upload succeded', 'data'=>$res))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Upload failed', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus($status); } } /* }}} */ function addDocumentLink($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No source document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No source document given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['documentid']) || $args['documentid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No target document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No target document given', 'data'=>''))->withStatus(400); return; } $sourcedoc = $dms->getDocument($args['id']); @@ -1137,21 +1164,21 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); $public = !isset($params['public']) ? true : false; if ($sourcedoc->addDocumentLink($targetdoc->getId(), $userobj->getID(), $public)){ - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not create document link', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not create document link', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on source document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on source document', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not find source or target document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find source or target document', 'data'=>''))->withStatus(500); } } /* }}} */ function getDocument($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1159,53 +1186,53 @@ class RestapiController { /* {{{ */ $lc = $document->getLatestContent(); if($lc) { $data = $this->__getLatestVersionData($lc); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function deleteDocument($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); if($document) { if ($document->getAccessMode($userobj, 'deleteDocument') >= M_READWRITE) { if($document->remove()) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Error removing document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Error removing document', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function moveDocument($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1213,35 +1240,35 @@ class RestapiController { /* {{{ */ if($folder = $dms->getFolder($args['folderid'])) { if($folder->getAccessMode($userobj, 'moveDocument') >= M_READWRITE) { if($document->setFolder($folder)) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Error moving document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Error moving document', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on destination folder', 'data'=>''))->withStatus(403); } } else { if($folder === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No destination folder', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No destination folder', 'data'=>''))->withStatus($status); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentContent($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1255,7 +1282,7 @@ class RestapiController { /* {{{ */ $file = $dms->contentDir . $lc->getPath(); if(!($fh = @fopen($file, 'rb'))) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } $stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body @@ -1271,24 +1298,24 @@ class RestapiController { /* {{{ */ sendFile($dms->contentDir . $lc->getPath()); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentVersions($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1298,25 +1325,25 @@ class RestapiController { /* {{{ */ foreach($lcs as $lc) { $recs[] = $this->__getDocumentVersionData($lc); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentVersion($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id']) || !ctype_digit($args['version'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1331,7 +1358,7 @@ class RestapiController { /* {{{ */ $file = $dms->contentDir . $lc->getPath(); if(!($fh = @fopen($file, 'rb'))) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } $stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body @@ -1347,23 +1374,23 @@ class RestapiController { /* {{{ */ sendFile($dms->contentDir . $lc->getPath()); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such version', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such version', 'data'=>''))->withStatus(404); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function updateDocumentVersion($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1373,29 +1400,29 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if (isset($params['comment'])) { $lc->setComment($params['comment']); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such version', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such version', 'data'=>''))->withStatus(404); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentFiles($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1407,25 +1434,25 @@ class RestapiController { /* {{{ */ foreach($files as $file) { $recs[] = $this->__getDocumentFileData($file); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentFile($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id']) || !ctype_digit($args['fileid'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1436,7 +1463,7 @@ class RestapiController { /* {{{ */ if($lc) { $file = $dms->contentDir . $lc->getPath(); if(!($fh = @fopen($file, 'rb'))) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } $stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body @@ -1452,26 +1479,26 @@ class RestapiController { /* {{{ */ sendFile($dms->contentDir . $lc->getPath()); } else { - return $response->withJson(array('success'=>false, 'message'=>'No document file', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document file', 'data'=>''))->withStatus(404); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentLinks($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1483,43 +1510,43 @@ class RestapiController { /* {{{ */ foreach($links as $link) { $recs[] = $this->__getDocumentLinkData($link); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentAttributes($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { if ($document->getAccessMode($userobj) >= M_READ) { $attributes = $this->__getAttributesData($document); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$attributes), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$attributes))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentContentAttributes($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $document = $dms->getDocument($args['id']); if($document) { @@ -1529,33 +1556,33 @@ class RestapiController { /* {{{ */ if($version) { if($version->getAccessMode($userobj) >= M_READ) { $attributes = $this->__getAttributesData($version); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$attributes), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$attributes))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on version', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on version', 'data'=>''))->withStatus(403); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No version', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No version', 'data'=>''))->withStatus(404); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function getDocumentPreview($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1582,7 +1609,7 @@ class RestapiController { /* {{{ */ $file = $previewer->getFileName($object, $args['width']).".png"; if(!($fh = @fopen($file, 'rb'))) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } $stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body @@ -1593,31 +1620,31 @@ class RestapiController { /* {{{ */ ->withHeader('Content-Length', $previewer->getFilesize($object)) ->withBody($stream); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document', 'data'=>''))->withStatus($status); } } /* }}} */ function addDocumentCategory($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['catid']) || $args['catid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No category given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No category given', 'data'=>''))->withStatus(400); return; } $cat = $dms->getDocumentCategory($args['catid']); @@ -1625,54 +1652,54 @@ class RestapiController { /* {{{ */ if($doc && $cat) { if($doc->getAccessMode($userobj, 'addDocumentCategory') >= M_READ) { if ($doc->addCategories([$cat])){ - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not add document category', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not add document category', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403); } } else { if(!$doc) - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus(404); if(!$cat) - return $response->withJson(array('success'=>false, 'message'=>'No such category', 'data'=>''), 404); - return $response->withJson(array('success'=>false, 'message'=>'Could not find category or document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such category', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find category or document', 'data'=>''))->withStatus(500); } } /* }}} */ function removeDocumentCategory($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id']) || !ctype_digit($args['catid'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); if(!$document) - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus(404); $category = $dms->getDocumentCategory($args['catid']); if(!$category) - return $response->withJson(array('success'=>false, 'message'=>'No such category', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such category', 'data'=>''))->withStatus(404); if ($document->getAccessMode($userobj, 'removeDocumentCategory') >= M_READWRITE) { $ret = $document->removeCategories(array($category)); if ($ret) - return $response->withJson(array('success'=>true, 'message'=>'Deleted category successfully.', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Deleted category successfully.', 'data'=>''))->withStatus(200); else - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } /* }}} */ function removeDocumentCategories($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $document = $dms->getDocument($args['id']); @@ -1680,38 +1707,38 @@ class RestapiController { /* {{{ */ if($document) { if ($document->getAccessMode($userobj, 'removeDocumentCategory') >= M_READWRITE) { if($document->setCategories(array())) - return $response->withJson(array('success'=>true, 'message'=>'Deleted categories successfully.', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'Deleted categories successfully.', 'data'=>''))->withStatus(200); else - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>''))->withStatus(500); } else { - return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access', 'data'=>''))->withStatus(403); } } else { if($document === null) $status=404; else $status=500; - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), $status); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus($status); } } /* }}} */ function setDocumentOwner($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!$userobj->isAdmin()) { - return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['userid']) || $args['userid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No user given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No user given', 'data'=>''))->withStatus(400); return; } $owner = $dms->getUser($args['userid']); @@ -1719,94 +1746,94 @@ class RestapiController { /* {{{ */ if($doc && $owner) { if($doc->getAccessMode($userobj, 'setDocumentOwner') > M_READ) { if ($doc->setOwner($owner)){ - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not set owner of document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not set owner of document', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403); } } else { if(!$doc) - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus(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 document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such user', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''))->withStatus(500); } } /* }}} */ function setDocumentAttribute($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $logger = $this->container->get('logger'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); return; } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['attrdefid']) || $args['attrdefid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''))->withStatus(400); return; } $attrdef = $dms->getAttributeDefinition($args['attrdefid']); $doc = $dms->getDocument($args['id']); if($doc && $attrdef) { if($attrdef->getObjType() !== SeedDMS_Core_AttributeDefinition::objtype_document) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for documents', 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for documents', 'data'=>''))->withStatus(409); } $params = $request->getParsedBody(); if(!isset($params['value'])) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''))->withStatus(400); } $new = $doc->getAttributeValue($attrdef) ? true : false; if(!$attrdef->validate($params['value'], $doc, $new)) { - return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''))->withStatus(400); } if($doc->getAccessMode($userobj, 'setDocumentAttribute') > M_READ) { if ($doc->setAttributeValue($attrdef, $params['value'])) { $logger->log("Setting attribute '".$attrdef->getName()."' (".$attrdef->getId().") to '".$params['value']."' successful", PEAR_LOG_INFO); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not set attribute value of document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not set attribute value of document', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403); } } else { if(!$doc) - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus(404); if(!$attrdef) - return $response->withJson(array('success'=>false, 'message'=>'No such attr definition', 'data'=>''), 404); - return $response->withJson(array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such attr definition', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''))->withStatus(500); } } /* }}} */ function setDocumentContentAttribute($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $logger = $this->container->get('logger'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); return; } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No document given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['version']) || $args['version'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No version number given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No version number given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['attrdefid']) || $args['attrdefid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''))->withStatus(400); return; } $attrdef = $dms->getAttributeDefinition($args['attrdefid']); @@ -1814,100 +1841,100 @@ class RestapiController { /* {{{ */ $version = $doc->getContentByVersion($args['version']); if($doc && $attrdef && $version) { if($attrdef->getObjType() !== SeedDMS_Core_AttributeDefinition::objtype_documentcontent) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for document versions', 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for document versions', 'data'=>''))->withStatus(409); } $params = $request->getParsedBody(); if(!isset($params['value'])) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''))->withStatus(400); } $new = $version->getAttributeValue($attrdef) ? true : false; if(!$attrdef->validate($params['value'], $version, $new)) { - return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''))->withStatus(400); } if($doc->getAccessMode($userobj, 'setDocumentContentAttribute') > M_READ) { if ($version->setAttributeValue($attrdef, $params['value'])) { $logger->log("Setting attribute '".$attrdef->getName()."' (".$attrdef->getId().") to '".$params['value']."' successful", PEAR_LOG_INFO); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not set attribute value of document content', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not set attribute value of document content', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on document', 'data'=>''))->withStatus(403); } } else { if(!$doc) - return $response->withJson(array('success'=>false, 'message'=>'No such document', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such document', 'data'=>''))->withStatus(404); if(!$version) - return $response->withJson(array('success'=>false, 'message'=>'No such version', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such version', 'data'=>''))->withStatus(404); if(!$attrdef) - return $response->withJson(array('success'=>false, 'message'=>'No such attr definition', 'data'=>''), 404); - return $response->withJson(array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such attr definition', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find user or document', 'data'=>''))->withStatus(500); } } /* }}} */ function setFolderAttribute($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $logger = $this->container->get('logger'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); return; } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No folder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['attrdefid']) || $args['attrdefid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No attribute definition id given', 'data'=>''))->withStatus(400); return; } $attrdef = $dms->getAttributeDefinition($args['attrdefid']); $obj = $dms->getFolder($args['id']); if($obj && $attrdef) { if($attrdef->getObjType() !== SeedDMS_Core_AttributeDefinition::objtype_folder) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for folders', 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute definition "'.$attrdef->getName().'" not suitable for folders', 'data'=>''))->withStatus(409); } $params = $request->getParsedBody(); if(!isset($params['value'])) { - return $response->withJson(array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''.$request->getHeader('Content-Type')[0]), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''.$request->getHeader('Content-Type')[0]))->withStatus(400); } if(strlen($params['value'])) { $new = $obj->getAttributeValue($attrdef) ? true : false; if(!$attrdef->validate($params['value'], $obj, $new)) { - return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''))->withStatus(400); } } if($obj->getAccessMode($userobj, 'setFolderAttribute') > M_READ) { if ($obj->setAttributeValue($attrdef, $params['value'])) { $logger->log("Setting attribute '".$attrdef->getName()."' (".$attrdef->getId().") to '".$params['value']."' successful", PEAR_LOG_INFO); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not set attribute value of folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not set attribute value of folder', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403); } } else { if(!$obj) - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); if(!$attrdef) - return $response->withJson(array('success'=>false, 'message'=>'No such attr definition', 'data'=>''), 404); - return $response->withJson(array('success'=>false, 'message'=>'Could not find user or folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such attr definition', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find user or folder', 'data'=>''))->withStatus(500); } } /* }}} */ function getAccount($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if($userobj) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getUserData($userobj)), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getUserData($userobj)))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } } /* }}} */ @@ -1918,8 +1945,8 @@ class RestapiController { /* {{{ */ * return a list of words only. */ function doSearch($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $params = $request->getQueryParams(); $querystr = $params['query']; @@ -1944,7 +1971,7 @@ class RestapiController { /* {{{ */ $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 $response->withJson(array(), 200); + return $this->renderer->json($response, array())->withStatus(200); } $entries = array(); $count = 0; @@ -2001,7 +2028,7 @@ class RestapiController { /* {{{ */ if($recs) // array_unshift($recs, array('type'=>'', 'id'=>0, 'name'=>$querystr, 'comment'=>'')); array_unshift($recs, ' '.$querystr); - return $response->withJson($recs, 200); + return $this->renderer->json($response, $recs)->withStatus(200); break; default: $recs = array(); @@ -2017,7 +2044,7 @@ class RestapiController { /* {{{ */ $recs[] = $this->__getFolderData($folder); } } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs)); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs)); break; } } /* }}} */ @@ -2027,8 +2054,8 @@ class RestapiController { /* {{{ */ * */ function doSearchByAttr($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $params = $request->getQueryParams(); $attrname = $params['name']; @@ -2070,26 +2097,28 @@ class RestapiController { /* {{{ */ $recs[] = $this->__getFolderData($folder); } } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$recs))->withStatus(200); } /* }}} */ function checkIfAdmin($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + if(!$this->container->has('userobj')) + echo "no user object"; - if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + if(!$this->container->has('userobj') || !($userobj = $this->container->get('userobj'))) { + return $this->renderer->json($response, ['success'=>false, 'message'=>'Not logged in', 'data'=>''])->withStatus(403); } + if(!$userobj->isAdmin()) { - return $response->withJson(array('success'=>false, 'message'=>'You must be logged in with an administrator account to access this resource', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must be logged in with an administrator account to access this resource', 'data'=>''))->withStatus(403); } return true; } /* }}} */ function getUsers($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; @@ -2099,12 +2128,12 @@ class RestapiController { /* {{{ */ foreach($users as $u) $data[] = $this->__getUserData($u); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function createUser($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2112,12 +2141,12 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if(empty(trim($params['user']))) { - return $response->withJson(array('success'=>false, 'message'=>'Missing user login', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Missing user login', 'data'=>''))->withStatus(400); } $userName = $params['user']; $password = isset($params['pass']) ? $params['pass'] : ''; if(empty(trim($params['name']))) { - return $response->withJson(array('success'=>false, 'message'=>'Missing full user name', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Missing full user name', 'data'=>''))->withStatus(400); } $fullname = $params['name']; $email = isset($params['email']) ? $params['email'] : ''; @@ -2129,16 +2158,16 @@ class RestapiController { /* {{{ */ $newAccount = $dms->addUser($userName, seed_pass_hash($password), $fullname, $email, $language, $theme, $comment, $roleid); if ($newAccount === false) { - return $response->withJson(array('success'=>false, 'message'=>'Account could not be created, maybe it already exists', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Account could not be created, maybe it already exists', 'data'=>''))->withStatus(500); } $result = $this->__getUserData($newAccount); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$result), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$result))->withStatus(201); } /* }}} */ function deleteUser($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2146,12 +2175,12 @@ class RestapiController { /* {{{ */ if($user = $dms->getUser($args['id'])) { if($result = $user->remove($userobj, $userobj)) { - return $response->withJson(array('success'=>$result, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>$result, 'message'=>'Could not delete user', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'Could not delete user', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such user', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such user', 'data'=>''))->withStatus(404); } } /* }}} */ @@ -2161,8 +2190,8 @@ class RestapiController { /* {{{ */ * @param $id The user name or numerical identifier */ function changeUserPassword($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2170,7 +2199,7 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if ($params['password'] == null) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply a new password', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new password', 'data'=>''))->withStatus(400); } $newPassword = $params['password']; @@ -2185,17 +2214,17 @@ class RestapiController { /* {{{ */ * User not found */ if (!$account) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'User not found.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'User not found.'))->withStatus(404); return; } $operation = $account->setPwd(seed_pass_hash($newPassword)); if (!$operation){ - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change password.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change password.'))->withStatus(404); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } /* }}} */ /** @@ -2204,8 +2233,8 @@ class RestapiController { /* {{{ */ * @param $id The user name or numerical identifier */ function changeUserQuota($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2213,7 +2242,7 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if ($params['quota'] == null) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply a new quota', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new quota', 'data'=>''))->withStatus(400); } $newQuota = $params['quota']; @@ -2228,22 +2257,22 @@ class RestapiController { /* {{{ */ * User not found */ if (!$account) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'User not found.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'User not found.'))->withStatus(404); return; } $operation = $account->setQuota($newQuota); if (!$operation){ - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change quota.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change quota.'))->withStatus(404); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } /* }}} */ function changeUserHomefolder($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2259,32 +2288,32 @@ class RestapiController { /* {{{ */ * User not found */ if (!$account) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'User not found.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'User not found.'))->withStatus(404); return; } if(!ctype_digit($args['folderid']) || $args['folderid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No homefolder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No homefolder given', 'data'=>''))->withStatus(400); return; } $newHomefolder = $dms->getFolder($args['folderid']); if (!$newHomefolder) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Folder not found.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Folder not found.'))->withStatus(404); return; } $operation = $account->setHomeFolder($newHomefolder->getId()); if (!$operation){ - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change homefolder.'), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change homefolder.'))->withStatus(404); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } /* }}} */ function getUserById($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2296,22 +2325,22 @@ class RestapiController { /* {{{ */ } if($account) { $data = $this->__getUserData($account); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such user', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such user', 'data'=>''))->withStatus(404); } } /* }}} */ function setDisabledUser($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; $params = $request->getParsedBody(); if (!isset($params['disable'])) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply a disabled state', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a disabled state', 'data'=>''))->withStatus(400); } $isDisabled = false; @@ -2329,15 +2358,15 @@ class RestapiController { /* {{{ */ if($account) { $account->setDisabled($isDisabled); $data = $this->__getUserData($account); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such user', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such user', 'data'=>''))->withStatus(404); } } /* }}} */ function getGroups($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2348,19 +2377,19 @@ class RestapiController { /* {{{ */ foreach($groups as $u) $data[] = $this->__getGroupData($u); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function createGroup($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; $params = $request->getParsedBody(); if (empty($params['name'])) { - return $response->withJson(array('success'=>false, 'message'=>'Need a group name.', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Need a group name.', 'data'=>''))->withStatus(400); } $groupName = $params['name']; @@ -2368,16 +2397,16 @@ class RestapiController { /* {{{ */ $newGroup = $dms->addGroup($groupName, $comment); if ($newGroup === false) { - return $response->withJson(array('success'=>false, 'message'=>'Group could not be created, maybe it already exists', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Group could not be created, maybe it already exists', 'data'=>''))->withStatus(500); } // $result = array('id'=>(int)$newGroup->getID()); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getGroupData($newGroup)), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getGroupData($newGroup)))->withStatus(201); } /* }}} */ function deleteGroup($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2385,18 +2414,18 @@ class RestapiController { /* {{{ */ if($group = $dms->getGroup($args['id'])) { if($result = $group->remove($userobj)) { - return $response->withJson(array('success'=>$result, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>$result, 'message'=>'Could not delete group', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'Could not delete group', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such group', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such group', 'data'=>''))->withStatus(404); } } /* }}} */ function getGroup($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2412,15 +2441,15 @@ class RestapiController { /* {{{ */ foreach ($group->getUsers() as $user) { $data['users'][] = array('id' => (int)$user->getID(), 'login' => $user->getLogin()); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such group', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such group', 'data'=>''))->withStatus(404); } } /* }}} */ function changeGroupMembership($request, $response, $args, $operationType) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2434,7 +2463,7 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if (empty($params['userid'])) { - return $response->withJson(array('success'=>false, 'message'=>'Missing userid', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Missing userid', 'data'=>''))->withStatus(400); } $userId = $params['userid']; if(ctype_digit($userId)) @@ -2465,7 +2494,7 @@ class RestapiController { /* {{{ */ { $message = 'Could not remove user from group.'; } - return $response->withJson(array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''))->withStatus(500); } $data = $this->__getGroupData($group); @@ -2473,7 +2502,7 @@ class RestapiController { /* {{{ */ foreach ($group->getUsers() as $userObj) { $data['users'][] = array('id' => (int)$userObj->getID(), 'login' => $userObj->getLogin()); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function addUserToGroup($request, $response, $args) { /* {{{ */ @@ -2485,8 +2514,8 @@ class RestapiController { /* {{{ */ } /* }}} */ function setFolderInheritsAccess($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2494,7 +2523,7 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if (!isset($params['enable'])) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply an "enable" value', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply an "enable" value', 'data'=>''))->withStatus(400); } $inherit = false; @@ -2517,29 +2546,29 @@ class RestapiController { /* {{{ */ // reread from db $folder = $dms->getFolder($folderId); $success = ($folder->inheritsAccess() == $inherit); - return $response->withJson(array('success'=>$success, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>$success, 'message'=>'', 'data'=>$data))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } } /* }}} */ function setFolderOwner($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!$userobj) { - return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Not logged in', 'data'=>''))->withStatus(403); } if(!$userobj->isAdmin()) { - return $response->withJson(array('success'=>false, 'message'=>'No access on folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403); } if(!ctype_digit($args['id']) || $args['id'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No folder given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No folder given', 'data'=>''))->withStatus(400); return; } if(!ctype_digit($args['userid']) || $args['userid'] == 0) { - return $response->withJson(array('success'=>false, 'message'=>'No user given', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No user given', 'data'=>''))->withStatus(400); return; } $owner = $dms->getUser($args['userid']); @@ -2547,19 +2576,19 @@ class RestapiController { /* {{{ */ if($folder && $owner) { if($folder->getAccessMode($userobj, 'setDocumentOwner') > M_READ) { if ($folder->setOwner($owner)){ - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not set owner of folder', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not set owner of folder', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No access on folder', 'data'=>''), 403); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No access on folder', 'data'=>''))->withStatus(403); } } else { if(!$doc) - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(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); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such user', 'data'=>''))->withStatus(404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not find user or folder', 'data'=>''))->withStatus(500); } } /* }}} */ @@ -2580,8 +2609,8 @@ class RestapiController { /* {{{ */ } /* }}} */ function changeFolderAccess($request, $response, $args, $operationType, $userOrGroup) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2593,7 +2622,7 @@ class RestapiController { /* {{{ */ $folder = $dms->getfolderByName($args['id']); } if (!$folder) { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } $params = $request->getParsedBody(); @@ -2602,12 +2631,12 @@ class RestapiController { /* {{{ */ { if ($params['id'] == null) { - return $response->withJson(array('success'=>false, 'message'=>'Please PUT the user or group Id', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Please PUT the user or group Id', 'data'=>''))->withStatus(400); } if ($params['mode'] == null) { - return $response->withJson(array('success'=>false, 'message'=>'Please PUT the access mode', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Please PUT the access mode', 'data'=>''))->withStatus(400); } $modeInput = $params['mode']; @@ -2677,47 +2706,47 @@ class RestapiController { /* {{{ */ { $message = 'Could not remove user/group access from this folder.'; } - return $response->withJson(array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''))->withStatus(500); } $data = array(); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function getCategories($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(false === ($categories = $dms->getDocumentCategories())) { - return $response->withJson(array('success'=>false, 'message'=>'Could not get categories', 'data'=>null), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not get categories', 'data'=>null))->withStatus(500); } $data = []; foreach($categories as $category) $data[] = $this->__getCategoryData($category); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ function getCategory($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $category = $dms->getDocumentCategory($args['id']); if($category) { - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($category)), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($category)))->withStatus(200); } else { - return $response->withJson(array('success'=>false, 'message'=>'No such category', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such category', 'data'=>''))->withStatus(404); } } /* }}} */ function createCategory($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $logger = $this->container->get('logger'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2725,25 +2754,25 @@ class RestapiController { /* {{{ */ $params = $request->getParsedBody(); if (empty($params['name'])) { - return $response->withJson(array('success'=>false, 'message'=>'Need a category.', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Need a category.', 'data'=>''))->withStatus(400); } $catobj = $dms->getDocumentCategoryByName($params['name']); if($catobj) { - return $response->withJson(array('success'=>false, 'message'=>'Category already exists', 'data'=>''), 409); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Category already exists', 'data'=>''))->withStatus(409); } else { if($data = $dms->addDocumentCategory($params['name'])) { $logger->log("Creating category '".$data->getName()."' (".$data->getId().") successful", PEAR_LOG_INFO); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($data)), 201); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($data)))->withStatus(201); } else { - return $response->withJson(array('success'=>false, 'message'=>'Could not add category', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Could not add category', 'data'=>''))->withStatus(500); } } } /* }}} */ function deleteCategory($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2751,12 +2780,12 @@ class RestapiController { /* {{{ */ if($category = $dms->getDocumentCategory($args['id'])) { if($result = $category->remove()) { - return $response->withJson(array('success'=>$result, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'', 'data'=>''))->withStatus(200); } else { - return $response->withJson(array('success'=>$result, 'message'=>'Could not delete category', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>$result, 'message'=>'Could not delete category', 'data'=>''))->withStatus(500); } } else { - return $response->withJson(array('success'=>false, 'message'=>'No such category', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such category', 'data'=>''))->withStatus(404); } } /* }}} */ @@ -2766,21 +2795,21 @@ class RestapiController { /* {{{ */ * @param $id The user name or numerical identifier */ function changeCategoryName($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $params = $request->getParsedBody(); if (empty($params['name'])) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''))->withStatus(400); } $newname = $params['name']; @@ -2791,26 +2820,26 @@ class RestapiController { /* {{{ */ * Category not found */ if (!$category) { - return $response->withJson(array('success'=>false, 'message'=>'No such category', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such category', 'data'=>''))->withStatus(404); } if (!$category->setName($newname)) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'))->withStatus(400); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($category)), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getCategoryData($category)))->withStatus(200); } /* }}} */ function getAttributeDefinitions($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $attrdefs = $dms->getAllAttributeDefinitions(); $data = []; foreach($attrdefs as $attrdef) $data[] = $this->__getAttributeDefinitionData($attrdef); - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ /** @@ -2819,20 +2848,20 @@ class RestapiController { /* {{{ */ * @param $id The user name or numerical identifier */ function changeAttributeDefinitionName($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; if(!ctype_digit($args['id'])) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Invalid parameter', 'data'=>''))->withStatus(400); } $params = $request->getParsedBody(); - if ($params['name'] == null) { - return $response->withJson(array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''), 400); + if (!isset($params['name']) || $params['name'] == null) { + return $this->renderer->json($response, array('success'=>false, 'message'=>'You must supply a new name', 'data'=>''))->withStatus(400); } $newname = $params['name']; @@ -2843,20 +2872,20 @@ class RestapiController { /* {{{ */ * Attribute definition not found */ if (!$attrdef) { - return $response->withJson(array('success'=>false, 'message'=>'No such attribute defintion', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such attribute defintion', 'data'=>''))->withStatus(404); } if (!$attrdef->setName($newname)) { - return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'), 400); + return $this->renderer->json($response, array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'))->withStatus(400); return; } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$this->__getAttributeDefinitionData($attrdef)), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$this->__getAttributeDefinitionData($attrdef)))->withStatus(200); } /* }}} */ function clearFolderAccessList($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); $check = $this->checkIfAdmin($request, $response); if($check !== true) @@ -2868,17 +2897,16 @@ class RestapiController { /* {{{ */ $folder = $dms->getFolderByName($args['id']); } if (!$folder) { - return $response->withJson(array('success'=>false, 'message'=>'No such folder', 'data'=>''), 404); + return $this->renderer->json($response, array('success'=>false, 'message'=>'No such folder', 'data'=>''))->withStatus(404); } if (!$folder->clearAccessList()) { - return $response->withJson(array('success'=>false, 'message'=>'Something went wrong. Could not clear access list for this folder.', 'data'=>''), 500); + return $this->renderer->json($response, array('success'=>false, 'message'=>'Something went wrong. Could not clear access list for this folder.', 'data'=>''))->withStatus(500); } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>''))->withStatus(200); } /* }}} */ function getStatsTotal($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; + $dms = $this->container->get('dms'); $check = $this->checkIfAdmin($request, $response); if($check !== true) return $check; @@ -2889,33 +2917,34 @@ class RestapiController { /* {{{ */ $data[$type] = $total; } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200); + return $this->renderer->json($response, array('success'=>true, 'message'=>'', 'data'=>$data))->withStatus(200); } /* }}} */ } /* }}} */ -class TestController { /* {{{ */ +final class SeedDMS_TestController { /* {{{ */ protected $container; + protected $renderer; // constructor receives container instance - public function __construct(ContainerInterface $container) { + public function __construct(ContainerInterface $container, JsonRenderer $renderer) { $this->container = $container; + $this->renderer = $renderer; } public function echoData($request, $response, $args) { /* {{{ */ - return $response->withJson(array('success'=>true, 'message'=>'This is the result of the echo call.', 'data'=>$args['data']), 200); + return $this->renderer->json($response, ['success'=>true, 'message'=>'This is the result of the echo call.', 'data'=>$args['data']]); } /* }}} */ public function version($request, $response, $args) { /* {{{ */ - $logger = $this->container->logger; + $logger = $this->container->get('logger'); $v = new SeedDMS_Version(); - return $response->withJson(array('success'=>true, 'message'=>'This is '.$v->banner(), 'data'=>['major'=>$v->majorVersion(), 'minor'=>$v->minorVersion(), 'subminor'=>$v->subminorVersion()]), 200); + return $this->renderer->json($response, ['success'=>true, 'message'=>'This is '.$v->banner(), 'data'=>['major'=>$v->majorVersion(), 'minor'=>$v->minorVersion(), 'subminor'=>$v->subminorVersion()]]); } /* }}} */ } /* }}} */ -/* Middleware for authentication */ -class RestapiAuth { /* {{{ */ +class RestapiCorsMiddleware implements MiddlewareInterface { /* {{{ */ private $container; @@ -2923,67 +2952,146 @@ class RestapiAuth { /* {{{ */ $this->container = $container; } + /** + * Example middleware invokable class + * + * @return \Psr\Http\Message\ResponseInterface + */ + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + { + $response = $handler->handle($request); + $response = $response + ->withHeader('Access-Control-Allow-Origin', $request->getHeader('Origin') ? $request->getHeader('Origin') : '*') + ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') + ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); + return $response; + } +} /* }}} */ + +/* Middleware for authentication */ +class RestapiAuthMiddleware implements MiddlewareInterface { /* {{{ */ + + private $container; + + private $responsefactory; + + public function __construct($container, $responsefactory) { + $this->container = $container; + $this->responsefactory = $responsefactory; + } + /** * Example middleware invokable class * * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request - * @param \Psr\Http\Message\ResponseInterface $response PSR7 response - * @param callable $next Next middleware + * @param \Psr\Http\Server\RequestHandlerInterface $handler * * @return \Psr\Http\Message\ResponseInterface */ - public function __invoke($request, $response, $next) + public function process( + ServerRequestInterface $request, + RequestHandlerInterface $handler): ResponseInterface { // $this->container has the DI - $dms = $this->container->dms; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + + $logger->log("Invoke AuthMiddleware for method ".$request->getMethod()." on '".$request->getUri()->getPath()."'".(isset($environment['HTTP_ORIGIN']) ? " with origin ".$environment['HTTP_ORIGIN'] : ''), PEAR_LOG_INFO); + $userobj = null; + /* Do not rely on $userobj being an object. It can be true, if a + * former authentication middleware has allowed access without + * authentification as a user. The paperless extension does this, + * for some endpoints, e.g. to get some general api information. + */ if($this->container->has('userobj')) - $userobj = $this->container->userobj; + $userobj = $this->container->get('userobj'); if($userobj) { - $response = $next($request, $response); + $logger->log("Already authenticated. Pass on to next middleware", PEAR_LOG_INFO); + $response = $handler->handle($request); return $response; } - $logger->log("Invoke middleware for method ".$request->getMethod()." on '".$request->getUri()->getPath()."'", PEAR_LOG_INFO); - $logger->log("Access with method ".$request->getMethod()." on '".$request->getUri()->getPath()."'".(isset($this->container->environment['HTTP_ORIGIN']) ? " with origin ".$this->container->environment['HTTP_ORIGIN'] : ''), PEAR_LOG_INFO); - if($settings->_apiOrigin && isset($this->container->environment['HTTP_ORIGIN'])) { + //$environment = $this->container->environment; // Slim 3 + $environment = $request->getServerParams(); + + if($settings->_apiOrigin && isset($environment['HTTP_ORIGIN'])) { $logger->log("Checking origin", PEAR_LOG_DEBUG); $origins = explode(',', $settings->_apiOrigin); - if(!in_array($this->container->environment['HTTP_ORIGIN'], $origins)) { - return $response->withStatus(403); + if(!in_array($environment['HTTP_ORIGIN'], $origins)) { + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Invalid origin', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } } /* The preflight options request doesn't have authorization in the header. So * don't even try to authorize. */ + $path = $environment['PATH_INFO'] ?? ''; if($request->getMethod() == 'OPTIONS') { $logger->log("Received preflight options request", PEAR_LOG_DEBUG); - } elseif(!in_array($request->getUri()->getPath(), array('login')) && substr($request->getUri()->getPath(), 0, 5) != 'echo/' && $request->getUri()->getPath() != 'version') { + } elseif(!in_array($path, array('/login')) && substr($path, 0, 6) != '/echo/' && $path != '/version') { $userobj = null; - if(!empty($this->container->environment['HTTP_AUTHORIZATION']) && !empty($settings->_apiKey) && !empty($settings->_apiUserId)) { - $logger->log("Authorization key: ".$this->container->environment['HTTP_AUTHORIZATION'], PEAR_LOG_DEBUG); - if($settings->_apiKey == $this->container->environment['HTTP_AUTHORIZATION']) { + $logger->log(var_export($environment, true), PEAR_LOG_DEBUG); + if(!empty($environment['HTTP_AUTHORIZATION']) && !empty($settings->_apiKey) && !empty($settings->_apiUserId)) { + $logger->log("Authorization key: ".$environment['HTTP_AUTHORIZATION'], PEAR_LOG_DEBUG); + if($settings->_apiKey == $environment['HTTP_AUTHORIZATION']) { if(!($userobj = $dms->getUser($settings->_apiUserId))) { - return $response->withJson(array('success'=>false, 'message'=>'Invalid user associated with api key', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Invalid user associated with api key', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } } else { - return $response->withJson(array('success'=>false, 'message'=>'Wrong api key', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Wrong api key', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } $logger->log("Login with apikey as '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); } else { + $logger->log("Checking for valid session", PEAR_LOG_INFO); require_once("../inc/inc.ClassSession.php"); $session = new SeedDMS_Session($dms->getDb()); if (isset($_COOKIE["mydms_session"])) { + $logger->log("Found cookie for session", PEAR_LOG_INFO); $dms_session = $_COOKIE["mydms_session"]; $logger->log("Session key: ".$dms_session, PEAR_LOG_DEBUG); if(!$resArr = $session->load($dms_session)) { /* Delete Cookie */ setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); $logger->log("Session for id '".$dms_session."' has gone", PEAR_LOG_ERR); - return $response->withJson(array('success'=>false, 'message'=>'Session has gone', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Session has gone', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } /* Load user data */ @@ -2993,41 +3101,85 @@ class RestapiAuth { /* {{{ */ setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); if($settings->_enableGuestLogin) { if(!($userobj = $dms->getUser($settings->_guestID))) - return $response->withJson(array('success'=>false, 'message'=>'Could not get guest login', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Could not get guest login', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } else - return $response->withJson(array('success'=>false, 'message'=>'Login as guest disabled', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Login as guest disable', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } + $logger->log("Authorization as user '".$userobj->getLogin()."'", PEAR_LOG_DEBUG); if($userobj->isAdmin()) { if($resArr["su"]) { - if(!($userobj = $dms->getUser($resArr["su"]))) - return $response->withJson(array('success'=>false, 'message'=>'Cannot substitute user', 'data'=>''), 403); + if(!($userobj = $dms->getUser($resArr["su"]))) { + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Cannot substitute user', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; + } } } -// $logger->log("Login with user name '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); + $logger->log("Login with user name '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); $dms->setUser($userobj); } else { - return $response->withJson(array('success'=>false, 'message'=>'Missing session cookie', 'data'=>''), 403); + $response = $this->responsefactory->createResponse(); + $response = $response->withHeader('Content-Type', 'application/json'); + $response = $response->withStatus(403); + $response->getBody()->write( + (string)json_encode( + ['success'=>false, 'message'=>'Missing session cookie', 'data'=>''], + JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR + ) + ); + return $response; } } - $this->container['userobj'] = $userobj; + $this->container->set('userobj', $userobj); } - $response = $next($request, $response); + $response = $handler->handle($request); + $logger->log("End AuthMiddleware for method ".$request->getMethod()." on '".$request->getUri()->getPath()."'", PEAR_LOG_INFO); return $response; } } /* }}} */ -$app = new \Slim\App(); +$containerBuilder = new ContainerBuilder(); +$c = $containerBuilder->build(); +AppFactory::setContainer($c); +$app = AppFactory::create(); $container = $app->getContainer(); -$container['dms'] = $dms; -$container['config'] = $settings; -$container['conversionmgr'] = $conversionmgr; -$container['logger'] = $logger; -$container['fulltextservice'] = $fulltextservice; -$container['notifier'] = $notifier; -$container['authenticator'] = $authenticator; +$container->set('dms', $dms); +$container->set('config', $settings); +$container->set('conversionmgr', $conversionmgr); +$container->set('logger', $logger); +$container->set('fulltextservice', $fulltextservice); +$container->set('notifier', $notifier); +$container->set('authenticator', $authenticator); -$app->add(new RestapiAuth($container)); +$app->setBasePath($settings->_httpRoot."restapi/index.php"); + +$app->add(new RestapiAuthMiddleware($container, $app->getResponseFactory())); if(isset($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'] as $hookObj) { @@ -3037,94 +3189,92 @@ if(isset($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'])) { } } +$app->addErrorMiddleware(true, true, true); + +$app->add(new RestapiCorsMiddleware($container)); + // Make CORS preflighted request possible $app->options('/{routes:.+}', function ($request, $response, $args) { return $response; }); -$app->add(function ($req, $res, $next) { - $response = $next($req, $res); - return $response - ->withHeader('Access-Control-Allow-Origin', $req->getHeader('Origin') ? $req->getHeader('Origin') : '*') - ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') - ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); -}); + // use post for create operation // use get for retrieval operation // use put for update operation // use delete for delete operation -$app->post('/login', \RestapiController::class.':doLogin'); -$app->get('/logout', \RestapiController::class.':doLogout'); -$app->get('/account', \RestapiController::class.':getAccount'); -$app->get('/search', \RestapiController::class.':doSearch'); -$app->get('/searchbyattr', \RestapiController::class.':doSearchByAttr'); -$app->get('/folder', \RestapiController::class.':getFolder'); -$app->get('/folder/{id}', \RestapiController::class.':getFolder'); -$app->post('/folder/{id}/move/{folderid}', \RestapiController::class.':moveFolder'); -$app->delete('/folder/{id}', \RestapiController::class.':deleteFolder'); -$app->get('/folder/{id}/children', \RestapiController::class.':getFolderChildren'); -$app->get('/folder/{id}/parent', \RestapiController::class.':getFolderParent'); -$app->get('/folder/{id}/path', \RestapiController::class.':getFolderPath'); -$app->get('/folder/{id}/attributes', \RestapiController::class.':getFolderAttributes'); -$app->put('/folder/{id}/attribute/{attrdefid}', \RestapiController::class.':setFolderAttribute'); -$app->post('/folder/{id}/folder', \RestapiController::class.':createFolder'); -$app->put('/folder/{id}/document', \RestapiController::class.':uploadDocumentPut'); -$app->post('/folder/{id}/document', \RestapiController::class.':uploadDocument'); -$app->get('/document/{id}', \RestapiController::class.':getDocument'); -$app->post('/document/{id}/attachment', \RestapiController::class.':uploadDocumentFile'); -$app->post('/document/{id}/update', \RestapiController::class.':updateDocument'); -$app->delete('/document/{id}', \RestapiController::class.':deleteDocument'); -$app->post('/document/{id}/move/{folderid}', \RestapiController::class.':moveDocument'); -$app->get('/document/{id}/content', \RestapiController::class.':getDocumentContent'); -$app->get('/document/{id}/versions', \RestapiController::class.':getDocumentVersions'); -$app->get('/document/{id}/version/{version}', \RestapiController::class.':getDocumentVersion'); -$app->put('/document/{id}/version/{version}', \RestapiController::class.':updateDocumentVersion'); -$app->get('/document/{id}/version/{version}/attributes', \RestapiController::class.':getDocumentContentAttributes'); -$app->put('/document/{id}/version/{version}/attribute/{attrdefid}', \RestapiController::class.':setDocumentContentAttribute'); -$app->get('/document/{id}/files', \RestapiController::class.':getDocumentFiles'); -$app->get('/document/{id}/file/{fileid}', \RestapiController::class.':getDocumentFile'); -$app->get('/document/{id}/links', \RestapiController::class.':getDocumentLinks'); -$app->post('/document/{id}/link/{documentid}', \RestapiController::class.':addDocumentLink'); -$app->get('/document/{id}/attributes', \RestapiController::class.':getDocumentAttributes'); -$app->put('/document/{id}/attribute/{attrdefid}', \RestapiController::class.':setDocumentAttribute'); -$app->get('/document/{id}/preview/{version}/{width}', \RestapiController::class.':getDocumentPreview'); -$app->delete('/document/{id}/categories', \RestapiController::class.':removeDocumentCategories'); -$app->delete('/document/{id}/category/{catid}', \RestapiController::class.':removeDocumentCategory'); -$app->post('/document/{id}/category/{catid}', \RestapiController::class.':addDocumentCategory'); -$app->put('/document/{id}/owner/{userid}', \RestapiController::class.':setDocumentOwner'); -$app->put('/account/fullname', \RestapiController::class.':setFullName'); -$app->put('/account/email', \RestapiController::class.':setEmail'); -$app->get('/account/documents/locked', \RestapiController::class.':getLockedDocuments'); -$app->get('/users', \RestapiController::class.':getUsers'); -$app->delete('/users/{id}', \RestapiController::class.':deleteUser'); -$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/{folderid}', \RestapiController::class.':changeUserHomefolder'); -$app->post('/groups', \RestapiController::class.':createGroup'); -$app->get('/groups', \RestapiController::class.':getGroups'); -$app->delete('/groups/{id}', \RestapiController::class.':deleteGroup'); -$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'); -$app->put('/folder/{id}/access/user/remove', \RestapiController::class.':removeUserAccessFromFolder'); -$app->put('/folder/{id}/access/clear', \RestapiController::class.':clearFolderAccessList'); -$app->get('/categories', \RestapiController::class.':getCategories'); -$app->get('/categories/{id}', \RestapiController::class.':getCategory'); -$app->delete('/categories/{id}', \RestapiController::class.':deleteCategory'); -$app->post('/categories', \RestapiController::class.':createCategory'); -$app->put('/categories/{id}/name', \RestapiController::class.':changeCategoryName'); -$app->get('/attributedefinitions', \RestapiController::class.':getAttributeDefinitions'); -$app->put('/attributedefinitions/{id}/name', \RestapiController::class.':changeAttributeDefinitionName'); -$app->get('/echo/{data}', \TestController::class.':echoData'); -$app->get('/version', \TestController::class.':version'); -$app->get('/statstotal', \RestapiController::class.':getStatsTotal'); +$app->post('/login', \SeedDMS_RestapiController::class.':doLogin'); +$app->get('/logout', \SeedDMS_RestapiController::class.':doLogout'); +$app->get('/account', \SeedDMS_RestapiController::class.':getAccount'); +$app->get('/search', \SeedDMS_RestapiController::class.':doSearch'); +$app->get('/searchbyattr', \SeedDMS_RestapiController::class.':doSearchByAttr'); +$app->get('/folder', \SeedDMS_RestapiController::class.':getFolder'); +$app->get('/folder/{id}', \SeedDMS_RestapiController::class.':getFolder'); +$app->post('/folder/{id}/move/{folderid}', \SeedDMS_RestapiController::class.':moveFolder'); +$app->delete('/folder/{id}', \SeedDMS_RestapiController::class.':deleteFolder'); +$app->get('/folder/{id}/children', \SeedDMS_RestapiController::class.':getFolderChildren'); +$app->get('/folder/{id}/parent', \SeedDMS_RestapiController::class.':getFolderParent'); +$app->get('/folder/{id}/path', \SeedDMS_RestapiController::class.':getFolderPath'); +$app->get('/folder/{id}/attributes', \SeedDMS_RestapiController::class.':getFolderAttributes'); +$app->put('/folder/{id}/attribute/{attrdefid}', \SeedDMS_RestapiController::class.':setFolderAttribute'); +$app->post('/folder/{id}/folder', \SeedDMS_RestapiController::class.':createFolder'); +$app->put('/folder/{id}/document', \SeedDMS_RestapiController::class.':uploadDocumentPut'); +$app->post('/folder/{id}/document', \SeedDMS_RestapiController::class.':uploadDocument'); +$app->get('/document/{id}', \SeedDMS_RestapiController::class.':getDocument'); +$app->post('/document/{id}/attachment', \SeedDMS_RestapiController::class.':uploadDocumentFile'); +$app->post('/document/{id}/update', \SeedDMS_RestapiController::class.':updateDocument'); +$app->delete('/document/{id}', \SeedDMS_RestapiController::class.':deleteDocument'); +$app->post('/document/{id}/move/{folderid}', \SeedDMS_RestapiController::class.':moveDocument'); +$app->get('/document/{id}/content', \SeedDMS_RestapiController::class.':getDocumentContent'); +$app->get('/document/{id}/versions', \SeedDMS_RestapiController::class.':getDocumentVersions'); +$app->get('/document/{id}/version/{version}', \SeedDMS_RestapiController::class.':getDocumentVersion'); +$app->put('/document/{id}/version/{version}', \SeedDMS_RestapiController::class.':updateDocumentVersion'); +$app->get('/document/{id}/version/{version}/attributes', \SeedDMS_RestapiController::class.':getDocumentContentAttributes'); +$app->put('/document/{id}/version/{version}/attribute/{attrdefid}', \SeedDMS_RestapiController::class.':setDocumentContentAttribute'); +$app->get('/document/{id}/files', \SeedDMS_RestapiController::class.':getDocumentFiles'); +$app->get('/document/{id}/file/{fileid}', \SeedDMS_RestapiController::class.':getDocumentFile'); +$app->get('/document/{id}/links', \SeedDMS_RestapiController::class.':getDocumentLinks'); +$app->post('/document/{id}/link/{documentid}', \SeedDMS_RestapiController::class.':addDocumentLink'); +$app->get('/document/{id}/attributes', \SeedDMS_RestapiController::class.':getDocumentAttributes'); +$app->put('/document/{id}/attribute/{attrdefid}', \SeedDMS_RestapiController::class.':setDocumentAttribute'); +$app->get('/document/{id}/preview/{version}/{width}', \SeedDMS_RestapiController::class.':getDocumentPreview'); +$app->delete('/document/{id}/categories', \SeedDMS_RestapiController::class.':removeDocumentCategories'); +$app->delete('/document/{id}/category/{catid}', \SeedDMS_RestapiController::class.':removeDocumentCategory'); +$app->post('/document/{id}/category/{catid}', \SeedDMS_RestapiController::class.':addDocumentCategory'); +$app->put('/document/{id}/owner/{userid}', \SeedDMS_RestapiController::class.':setDocumentOwner'); +$app->put('/account/fullname', \SeedDMS_RestapiController::class.':setFullName'); +$app->put('/account/email', \SeedDMS_RestapiController::class.':setEmail'); +$app->get('/account/documents/locked', \SeedDMS_RestapiController::class.':getLockedDocuments'); +$app->get('/users', \SeedDMS_RestapiController::class.':getUsers'); +$app->delete('/users/{id}', \SeedDMS_RestapiController::class.':deleteUser'); +$app->post('/users', \SeedDMS_RestapiController::class.':createUser'); +$app->get('/users/{id}', \SeedDMS_RestapiController::class.':getUserById'); +$app->put('/users/{id}/disable', \SeedDMS_RestapiController::class.':setDisabledUser'); +$app->put('/users/{id}/password', \SeedDMS_RestapiController::class.':changeUserPassword'); +$app->put('/users/{id}/quota', \SeedDMS_RestapiController::class.':changeUserQuota'); +$app->put('/users/{id}/homefolder/{folderid}', \SeedDMS_RestapiController::class.':changeUserHomefolder'); +$app->post('/groups', \SeedDMS_RestapiController::class.':createGroup'); +$app->get('/groups', \SeedDMS_RestapiController::class.':getGroups'); +$app->delete('/groups/{id}', \SeedDMS_RestapiController::class.':deleteGroup'); +$app->get('/groups/{id}', \SeedDMS_RestapiController::class.':getGroup'); +$app->put('/groups/{id}/addUser', \SeedDMS_RestapiController::class.':addUserToGroup'); +$app->put('/groups/{id}/removeUser', \SeedDMS_RestapiController::class.':removeUserFromGroup'); +$app->put('/folder/{id}/setInherit', \SeedDMS_RestapiController::class.':setFolderInheritsAccess'); +$app->put('/folder/{id}/owner/{userid}', \SeedDMS_RestapiController::class.':setFolderOwner'); +$app->put('/folder/{id}/access/group/add', \SeedDMS_RestapiController::class.':addGroupAccessToFolder'); // +$app->put('/folder/{id}/access/user/add', \SeedDMS_RestapiController::class.':addUserAccessToFolder'); // +$app->put('/folder/{id}/access/group/remove', \SeedDMS_RestapiController::class.':removeGroupAccessFromFolder'); +$app->put('/folder/{id}/access/user/remove', \SeedDMS_RestapiController::class.':removeUserAccessFromFolder'); +$app->put('/folder/{id}/access/clear', \SeedDMS_RestapiController::class.':clearFolderAccessList'); +$app->get('/categories', \SeedDMS_RestapiController::class.':getCategories'); +$app->get('/categories/{id}', \SeedDMS_RestapiController::class.':getCategory'); +$app->delete('/categories/{id}', \SeedDMS_RestapiController::class.':deleteCategory'); +$app->post('/categories', \SeedDMS_RestapiController::class.':createCategory'); +$app->put('/categories/{id}/name', \SeedDMS_RestapiController::class.':changeCategoryName'); +$app->get('/attributedefinitions', \SeedDMS_RestapiController::class.':getAttributeDefinitions'); +$app->put('/attributedefinitions/{id}/name', \SeedDMS_RestapiController::class.':changeAttributeDefinitionName'); +$app->get('/echo/{data}', \SeedDMS_TestController::class.':echoData'); +$app->get('/version', \SeedDMS_TestController::class.':version'); +$app->get('/statstotal', \SeedDMS_RestapiController::class.':getStatsTotal'); if(isset($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'])) { foreach($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'] as $hookObj) {