From 1efa539732da6eaf8db22c50601f91214eaa6d14 Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Thu, 27 Feb 2020 11:20:06 +0100 Subject: [PATCH] FEAT #13119 TIME 0:45 added document information route --- rest/index.php | 1 + .../resource/controllers/ResController.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/rest/index.php b/rest/index.php index 1d8cce6b66e..58577f8a47b 100755 --- a/rest/index.php +++ b/rest/index.php @@ -379,6 +379,7 @@ $app->get('/resources/{resId}/emailsInitialization', \Email\controllers\EmailCon $app->get('/resources/{resId}/fields/{fieldId}', \Resource\controllers\ResController::class . ':getField'); $app->delete('/resources/{resId}/linkedResources/{id}', \Resource\controllers\LinkController::class . ':unlinkResources'); $app->delete('/resources/{resId}/circuits/{type}', \Entity\controllers\ListInstanceController::class . ':deleteCircuit'); +$app->get('/resources/{resId}/fileInformation', \Resource\controllers\ResController::class . ':getResourceFileInformation'); $app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus'); $app->post('/res/list', \Resource\controllers\ResController::class . ':getList'); diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 46acc801f89..d9f48f55b6b 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -1232,4 +1232,23 @@ class ResController extends ResourceControlController return $response->withJson(['listEventData' => $listEventData]); } + + public function getResourceFileInformation(Request $request, Response $response, array $args) + { + if (!ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + + $resource = ResModel::getById([ + 'resId' => $args['resId'], + 'select' => ['format', 'fingerprint', 'filesize', 'fulltext_result'] + ]); + + $allowedFiles = StoreController::getAllowedFiles(); + $allowedFiles = array_column($allowedFiles, 'extension'); + + $resource['canConvert'] = in_array(strtoupper($resource['format']), $allowedFiles); + + return $response->withJson(['information' => $resource]); + } } -- GitLab