diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql index 0112f77f97b4faadf39a403423ba2be63e46463c..ff6bbbc2c55d20aeee825214f4e0bc3031076843 100644 --- a/migration/19.12/1912.sql +++ b/migration/19.12/1912.sql @@ -158,6 +158,8 @@ CREATE TABLE indexing_models_fields ) WITH (OIDS=FALSE); +ALTER TABLE res_letterbox ADD COLUMN model_id INTEGER; + /* TAGS */ DO $$ BEGIN @@ -318,11 +320,13 @@ WHERE service_id = 'edit_recipient_outside_process' OR service_id = 'update_diff DELETE FROM usergroups_services WHERE service_id = 'edit_recipient_outside_process'; DELETE FROM usergroups_services WHERE service_id = 'update_list_diff_in_details'; DELETE FROM usergroups_services WHERE service_id = 'edit_recipient_in_process'; +UPDATE priorities SET delays = 30 WHERE delays IS NULL; /* REFACTORING MODIFICATION */ ALTER TABLE notif_email_stack ALTER COLUMN attachments TYPE text; ALTER TABLE tags ALTER COLUMN label TYPE character varying(128); +ALTER TABLE priorities ALTER COLUMN delays SET NOT NULL; /* REFACTORING SUPPRESSION */ @@ -363,12 +367,8 @@ DROP TABLE IF EXISTS foldertypes_doctypes_level1; DROP TABLE IF EXISTS foldertypes_indexes; ALTER TABLE doctypes DROP COLUMN IF EXISTS coll_id; DROP TABLE IF EXISTS mlb_doctype_ext; -ALTER TABLE res_letterbox ADD COLUMN model_id INTEGER; - -/* PRIORITIES */ ALTER TABLE priorities DROP COLUMN IF EXISTS working_days; -UPDATE priorities SET delays = 30 WHERE delays IS NULL; -ALTER TABLE priorities ALTER COLUMN delays SET NOT NULL; + /* RE CREATE VIEWS */ CREATE OR REPLACE VIEW res_view_letterbox AS diff --git a/rest/index.php b/rest/index.php index ea787c03c937e7c6539c42ec3793b1a2dc1c5010..90c631399d298bbf4ae4ca2eb8147aefceb0e4db 100755 --- a/rest/index.php +++ b/rest/index.php @@ -216,6 +216,7 @@ $app->put('/groups/{id}/reassign/{newGroupId}', \Group\controllers\GroupControll //Histories $app->get('/histories', \History\controllers\HistoryController::class . ':get'); $app->get('/histories/users/{userSerialId}', \History\controllers\HistoryController::class . ':getByUserId'); +$app->get('/histories/resources/{resId}', \History\controllers\HistoryController::class . ':getByResourceId'); //Header $app->get('/header', \SrcCore\controllers\CoreController::class . ':getHeader'); diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index c09c29764fdb706802ef7e9b2b69c69c67e2159b..ca7fc39c21e49ed5715c3204a05b801d282336a3 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -14,6 +14,7 @@ namespace History\controllers; +use Resource\controllers\ResController; use Respect\Validation\Validator; use SrcCore\controllers\LogsController; use Group\models\ServiceModel; @@ -106,4 +107,15 @@ 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]); + } } diff --git a/src/app/history/models/HistoryModelAbstract.php b/src/app/history/models/HistoryModelAbstract.php index b1ede87ac4187a9a1c696d482edff7c7d43ee9e6..f9a31bc55948bcec37d9823f06aaa9388b550402 100755 --- a/src/app/history/models/HistoryModelAbstract.php +++ b/src/app/history/models/HistoryModelAbstract.php @@ -77,6 +77,23 @@ 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 = ?', 'event_date > (CURRENT_TIMESTAMP - interval \'30 DAYS\')'], + 'data' => [['res_letterbox', 'res_view_letterbox'], $args['resId']], + 'order_by' => ['event_date DESC'], + 'limit' => 200 + ]); + + return $history; + } + public static function getFilter(array $aArgs = []) { ValidatorModel::notEmpty($aArgs, ['select','event_date']);