diff --git a/rest/index.php b/rest/index.php index 6891e0d342bf31a5ce04118060c0dbcd64930786..34984544395c2fba42f99953ae5843b33358337a 100755 --- a/rest/index.php +++ b/rest/index.php @@ -251,7 +251,6 @@ $app->get('/groups/{id}/privileges/{privilegeId}/parameters', \Group\controllers $app->get('/history', \History\controllers\HistoryController::class . ':get'); $app->get('/history/availableFilters', \History\controllers\HistoryController::class . ':getAvailableFilters'); $app->get('/history/users/{userSerialId}', \History\controllers\HistoryController::class . ':getByUserId'); -$app->get('/history/resources/{resId}', \History\controllers\HistoryController::class . ':getByResourceId'); $app->get('/history/resources/{resId}/workflow', \History\controllers\HistoryController::class . ':getWorkflowByResourceId'); //BatchHistory diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index 475e94d286d31cbb39e24a7eefa74ca1149b5dba..7876444a71a77ec9525eb7c84c60e3cd6759f90c 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -30,12 +30,13 @@ class HistoryController { public function get(Request $request, Response $response) { - if (!PrivilegeController::hasPrivilege(['privilegeId' => 'view_history', 'userId' => $GLOBALS['id']])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - $queryParams = $request->getQueryParams(); + $service = PrivilegeController::hasPrivilege(['privilegeId' => 'view_history', 'userId' => $GLOBALS['id']]); + if (!$service && (!Validator::intVal()->notEmpty()->validate($queryParams['resId']) || !ResController::hasRightByResId(['resId' => [$queryParams['resId']], 'userId' => $GLOBALS['id']]))) { + return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); + } + $limit = 25; if (!empty($queryParams['limit']) && is_numeric($queryParams['limit'])) { $limit = (int)$queryParams['limit']; @@ -75,6 +76,13 @@ class HistoryController $where[] = 'event_date < ?'; $data[] = $queryParams['endDate']; } + if (!empty($queryParams['resId'])) { + $where[] = 'table_name in (?)'; + $data[] = ['res_letterbox', 'res_view_letterbox']; + + $where[] = 'record_id = ?'; + $data[] = $queryParams['resId']; + } $eventTypes = []; if (!empty($queryParams['actions']) && is_array($queryParams['actions'])) { @@ -163,17 +171,6 @@ class HistoryController return $response->withJson(['histories' => $aHistories]); } - public function getByResourceId(Request $request, Response $response, array $args) - { - if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - - $history = HistoryModel::getByResourceId(['resId' => $args['resId'], 'select' => ['info', 'event_date']]); - - return $response->withJson(['history' => $history]); - } - public function getWorkflowByResourceId(Request $request, Response $response, array $args) { if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) { diff --git a/src/app/history/models/HistoryModelAbstract.php b/src/app/history/models/HistoryModelAbstract.php index 923468c8601e154fc51737f51339216cd6a2c4a7..ad5806de4cd9f698ec87d145e66e69dc1ca6fd51 100755 --- a/src/app/history/models/HistoryModelAbstract.php +++ b/src/app/history/models/HistoryModelAbstract.php @@ -78,23 +78,6 @@ abstract class HistoryModelAbstract return $aHistories; } - public static function getByResourceId(array $args) - { - ValidatorModel::notEmpty($args, ['resId']); - ValidatorModel::stringType($args, ['resId']); - - $history = DatabaseModel::select([ - 'select' => empty($args['select']) ? ['*'] : $args['select'], - 'table' => ['history'], - 'where' => ['table_name in (?)', 'record_id = ?'], - 'data' => [['res_letterbox', 'res_view_letterbox'], $args['resId']], - 'order_by' => ['event_date DESC'], - 'limit' => 500 - ]); - - return $history; - } - public static function getWorkflowByResourceId(array $args) { ValidatorModel::notEmpty($args, ['resId']); diff --git a/test/unitTests/app/history/HistoryControllerTest.php b/test/unitTests/app/history/HistoryControllerTest.php index b264094e8c9e30dd7973a608cf93629390284741..e0e0f72ba30abcd8220e340f26bb836a3da0dbc5 100755 --- a/test/unitTests/app/history/HistoryControllerTest.php +++ b/test/unitTests/app/history/HistoryControllerTest.php @@ -35,7 +35,7 @@ class HistoryControllerTest extends TestCase $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'startDate' => '1521100000', + 'startDate' => '15-03-2018', 'endDate' => time() ]; $fullRequest = $request->withQueryParams($aArgs); @@ -56,7 +56,7 @@ class HistoryControllerTest extends TestCase $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'startDate' => '1521100000', + 'startDate' => '15-03-2018', 'endDate' => time() ]; $fullRequest = $request->withQueryParams($aArgs);