diff --git a/lang/en.json b/lang/en.json index 0a70b5f5e297c53baaa4d14f636862db026ec658..500b462e51d98b63ee1c3ef212a0568b3bc7ac3a 100755 --- a/lang/en.json +++ b/lang/en.json @@ -123,22 +123,23 @@ "userPasswordUpdated" : "User password updated", "userSignatureAdded" : "User signature added", "userSignatureDeleted" : "User signature deleted", - "userUpdated" : "User updated", - "userDeleted" : "User deleted", - "userViewed" : "User viewed", - "userHasCurrentDocuments" : "User has current documents", + "userUpdated" : "User updated", + "userDeleted" : "User deleted", + "userViewed" : "User viewed", + "userHistoryViewed" : "User history viewed", + "userHasCurrentDocuments" : "User has current documents", "userLoginAlreadyExists" : "User login already exists", - "validate" : "Validate", - "validateAnnotation" : "Validate the annotation", - "validateDocumentWithoutSignOrNote" : "You are about to validate this document without signature or annotation!", - "wantDeleteSignature" : "Do you want to delete this signature?", - "wantDeleteSignatureOtherPage" : "Do you want to delete the signature on the other pages?", - "wantSignOtherPage" : "Do you want to sign the other pages?", - "warning" : "Warning", - "wouldLikeConfirm" : "Would you like to confirm?", - "wrongLoginPassword" : "Wrong login or password", - "wrongPassword" : "Wrong password", - "wsUser" : "Web service user", + "validate" : "Validate", + "validateAnnotation" : "Validate the annotation", + "validateDocumentWithoutSignOrNote" : "You are about to validate this document without signature or annotation!", + "wantDeleteSignature" : "Do you want to delete this signature?", + "wantDeleteSignatureOtherPage" : "Do you want to delete the signature on the other pages?", + "wantSignOtherPage" : "Do you want to sign the other pages?", + "warning" : "Warning", + "wouldLikeConfirm" : "Would you like to confirm?", + "wrongLoginPassword" : "Wrong login or password", + "wrongPassword" : "Wrong password", + "wsUser" : "Web service user", "visaUser": "Visa user", "signUser": "Sign user", "visaProcessInfo": "Visa to", diff --git a/lang/fr.json b/lang/fr.json index c81c0291a2238ca9f482d1288066ee8cbf3fb1fc..215c3a35b74474cb8ea82272a42c9bdb9eb65a71 100755 --- a/lang/fr.json +++ b/lang/fr.json @@ -123,23 +123,24 @@ "userPasswordUpdated" : "Mot de passe utilisateur modifié", "userSignatureAdded" : "Signature utilisateur ajoutée", "userSignatureDeleted" : "Signature utilisateur supprimée", - "userUpdated" : "Utilisateur modifié", - "userDeleted" : "Utilisateur supprimé", - "userViewed" : "Utilisateur consulté", - "userHasCurrentDocuments" : "L'utilisateur a des documents en cours", + "userUpdated" : "Utilisateur modifié", + "userDeleted" : "Utilisateur supprimé", + "userViewed" : "Utilisateur consulté", + "userHistoryViewed" : "Historique utilisateur consulté", + "userHasCurrentDocuments" : "L'utilisateur a des documents en cours", "userLoginAlreadyExists" : "L'identifiant utilisateur existe déjà ", "validate" : "Valider", - "validateAnnotation" : "Valider l'annotation", - "validateDocumentWithoutSignOrNote" : "Vous êtes sur le point de valider ce document sans signature ou annotation !", - "wantDeleteSignature" : "Voulez-vous supprimer cette signature ?", - "wantDeleteSignatureOtherPage" : "Voulez-vous supprimer la signature sur les autres pages ?", - "wantSignOtherPage" : "Voulez-vous apposer la signature sur les autres pages ?", - "warning" : "Attention", - "wouldLikeConfirm" : "Souhaitez-vous confirmer ?", - "wrongLoginPassword" : "Mauvais identifiant ou mauvais mot de passe", - "wrongPassword" : "Mauvais mot de passe", - "wsUser" : "Utilisateur web service", - "visaUser" : "Viseur", + "validateAnnotation" : "Valider l'annotation", + "validateDocumentWithoutSignOrNote" : "Vous êtes sur le point de valider ce document sans signature ou annotation !", + "wantDeleteSignature" : "Voulez-vous supprimer cette signature ?", + "wantDeleteSignatureOtherPage" : "Voulez-vous supprimer la signature sur les autres pages ?", + "wantSignOtherPage" : "Voulez-vous apposer la signature sur les autres pages ?", + "warning" : "Attention", + "wouldLikeConfirm" : "Souhaitez-vous confirmer ?", + "wrongLoginPassword" : "Mauvais identifiant ou mauvais mot de passe", + "wrongPassword" : "Mauvais mot de passe", + "wsUser" : "Utilisateur web service", + "visaUser" : "Viseur", "signUser": "Signataire", "visaProcessInfo": "Visé le", "signProcessInfo": "Signé le", diff --git a/rest/index.php b/rest/index.php index daec24822be97b9b1b50a7db2dff2b850aa1ec83..0ccc1560002199f7635433b4d84a320b1b39cff8 100755 --- a/rest/index.php +++ b/rest/index.php @@ -104,6 +104,7 @@ $app->delete('/users/{id}', \User\controllers\UserController::class . ':delete') $app->get('/users/{id}/picture', \User\controllers\UserController::class . ':getPictureById'); $app->put('/users/{id}/preferences', \User\controllers\UserController::class . ':updatePreferences'); $app->put('/users/{id}/password', \User\controllers\UserController::class . ':updatePassword'); +$app->get('/users/{id}/history', \History\controllers\HistoryController::class . ':getByUserId'); $app->post('/password', \User\controllers\UserController::class . ':forgotPassword'); $app->put('/password', \User\controllers\UserController::class . ':updateForgottenPassword'); diff --git a/sql/structure.sql b/sql/structure.sql index 06109de210501414eef4c57cdd87a001d8204507..a680553dc548880ecfae2780ee4ee626a89e3a99 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -125,6 +125,7 @@ CREATE TABLE history object_type CHARACTER VARYING(128) NOT NULL, object_id CHARACTER VARYING(32) NOT NULL, type CHARACTER VARYING(64) NOT NULL, + user_id INTEGER NOT NULL, "user" text NOT NULL, date TIMESTAMP without TIME ZONE NOT NULL, message text NOT NULL, diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index 2eb0660db175dae144bb345a1ff2542226dbf901..f946dcd2d3939779510eed392459e101b5b59a96 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -17,12 +17,12 @@ namespace History\controllers; use Document\controllers\DocumentController; use Document\models\DocumentModel; use Group\controllers\PrivilegeController; +use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; use SrcCore\controllers\LanguageController; use SrcCore\models\ValidatorModel; use History\models\HistoryModel; -use User\controllers\UserController; use User\models\UserModel; class HistoryController @@ -38,6 +38,7 @@ class HistoryController 'object_type' => $args['objectType'], 'object_id' => $args['objectId'], 'type' => $args['type'], + 'user_id' => $GLOBALS['id'], 'user' => UserModel::getLabelledUserById(['id' => $GLOBALS['id']]), 'message' => $args['message'], 'data' => empty($args['data']) ? '{}' : json_encode($args['data']), @@ -53,6 +54,10 @@ class HistoryController return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } + if (!Validator::intVal()->notEmpty()->validate($args['id'])) { + return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); + } + $document = DocumentModel::getById(['select' => [1], 'id' => $args['id']]); if (empty($document)) { return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']); @@ -99,4 +104,61 @@ class HistoryController return $response->withJson(['history' => $formattedHistory]); } + + public function getByUserId(Request $request, Response $response, array $args) + { + if ($GLOBALS['id'] != $args['id'] && !PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) { + return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); + } + + if (!Validator::intVal()->notEmpty()->validate($args['id'])) { + return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); + } + + $user = UserModel::getById(['select' => [1], 'id' => $args['id']]); + if (empty($user)) { + return $response->withStatus(400)->withJson(['errors' => 'User does not exist']); + } + + $history = HistoryModel::get([ + 'select' => ['code', 'type', '"user"', 'date', 'message', 'data'], + 'where' => ["(object_type = ? AND object_id = ?) OR (data->>'userId' = ?) OR (user_id = ?)"], + 'data' => ['main_documents', $args['id'], $args['id'], $args['id']], + 'orderBy' => ['date'] + ]); + + $formattedHistory = []; + + $lang = LanguageController::get(); + $langKeys = []; + $langValues = []; + foreach ($lang as $key => $value) { + $langKeys[] = "/{{$key}}/"; + $langValues[] = $value; + } + + foreach ($history as $value) { + $date = new \DateTime($value['date']); + + $formattedHistory[] = [ + 'code' => $value['code'], + 'type' => $value['type'], + 'user' => $value['user'], + 'date' => $date->format('d-m-Y H:i'), + 'message' => preg_replace($langKeys, $langValues, $value['message']), + 'data' => json_decode($value['data'], true) + ]; + } + + HistoryController::add([ + 'code' => 'OK', + 'objectType' => 'history', + 'objectId' => $args['id'], + 'type' => 'VIEW', + 'message' => '{userHistoryViewed}', + 'data' => ['objectType' => 'users'] + ]); + + return $response->withJson(['history' => $formattedHistory]); + } } diff --git a/src/app/history/models/HistoryModel.php b/src/app/history/models/HistoryModel.php index ba27183800f728b463e57d24d1fb0b1f3b3abafa..ebfde00211c3a5b0e6331b62dde6d352d5c3a7d9 100755 --- a/src/app/history/models/HistoryModel.php +++ b/src/app/history/models/HistoryModel.php @@ -40,8 +40,9 @@ class HistoryModel public static function create(array $args) { - ValidatorModel::notEmpty($args, ['code', 'object_type', 'object_id', 'type', 'user', 'message', 'data', 'ip']); + ValidatorModel::notEmpty($args, ['code', 'object_type', 'object_id', 'type', 'user_id', 'user', 'message', 'data', 'ip']); ValidatorModel::stringType($args, ['code', 'object_type', 'type', 'user', 'message', 'data', 'ip']); + ValidatorModel::intVal($args, ['user_id']); DatabaseModel::insert([ 'table' => 'history', @@ -50,6 +51,7 @@ class HistoryModel 'object_type' => $args['object_type'], 'object_id' => $args['object_id'], 'type' => $args['type'], + 'user_id' => $args['user_id'], '"user"' => $args['user'], 'date' => 'CURRENT_TIMESTAMP', 'message' => $args['message'],