From e780b75cc7299222bd0b0f3f3521e354554d740b Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Fri, 28 May 2021 11:06:36 +0200
Subject: [PATCH] FEAT #16982 TIME 1 User phone

---
 sql/structure.sql                           |  1 +
 src/app/user/controllers/UserController.php | 12 ++++++------
 src/app/user/models/UserModel.php           |  3 ++-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/sql/structure.sql b/sql/structure.sql
index 53c1a7e4aa..7e64bba36c 100755
--- a/sql/structure.sql
+++ b/sql/structure.sql
@@ -217,6 +217,7 @@ CREATE TABLE users
   "password" character varying(255) NOT NULL,
   firstname character varying(128) NOT NULL,
   lastname character varying(128) NOT NULL,
+  phone character varying(128),
   picture text,
   "isRest" boolean DEFAULT FALSE NOT NULL,
   preferences jsonb NOT NULL DEFAULT '{"lang" : "fr", "writingMode" : "direct", "writingSize" : 1, "writingColor" : "#000000", "notifications" : true}',
diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php
index 3d7b80654a..1c6f1c70ff 100755
--- a/src/app/user/controllers/UserController.php
+++ b/src/app/user/controllers/UserController.php
@@ -46,7 +46,7 @@ class UserController
     {
         $queryParams = $request->getQueryParams();
 
-        $select = ['id', 'firstname', 'lastname', 'substitute', 'x509_fingerprint'];
+        $select = ['id', 'firstname', 'lastname', 'email', 'phone', 'substitute', 'x509_fingerprint'];
         $where = [];
         $queryData = [];
         if (empty($queryParams['mode'])) {
@@ -55,7 +55,6 @@ class UserController
         }
         if (PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) {
             $select[] = 'login';
-            $select[] = 'email';
         }
 
         $users = UserModel::get([
@@ -140,7 +139,7 @@ class UserController
         if (!empty($existingUser)) {
             return $response->withStatus(400)->withJson(['errors' => 'Login already exists', 'lang' => 'userLoginAlreadyExists']);
         }
-        
+
         $body['x509_fingerprint'] = $body['x509Fingerprint'];
 
         if (!empty($body['isRest'])) {
@@ -214,6 +213,7 @@ class UserController
             'firstname'       => $body['firstname'],
             'lastname'        => $body['lastname'],
             'email'           => $body['email'],
+            'phone'           => $body['phone'],
             'signature_modes' => []
         ];
 
@@ -366,14 +366,14 @@ class UserController
                 'where'  => ['main_document_id in (?)', "process_date IS NULL", "status IS NULL"],
                 'data'   => [$mainDocumentId]
             ]);
-            
+
             $workflowsId = array_column($workflows, 'id');
             WorkflowModel::update([
                 'set'   => ['status' => 'STOP', 'process_date' => 'CURRENT_TIMESTAMP'],
                 'where' => ['id in (?)', "process_date IS NULL AND status IS NULL"],
                 'data'  => [$workflowsId]
             ]);
-    
+
             $previousDocumentId = null;
             foreach ($workflows as $step) {
                 $document = DocumentModel::getById(['select' => ['typist', 'id'], 'id' => $step['main_document_id']]);
@@ -748,7 +748,7 @@ class UserController
         ValidatorModel::notEmpty($args, ['id']);
         ValidatorModel::intVal($args, ['id']);
 
-        $user = UserModel::getById(['select' => ['id', 'login', 'email', 'firstname', 'lastname', 'picture', 'preferences', 'substitute', '"isRest"', 'signature_modes', 'x509_fingerprint'], 'id' => $args['id']]);
+        $user = UserModel::getById(['select' => ['id', 'login', 'email', 'firstname', 'lastname', 'phone', 'picture', 'preferences', 'substitute', '"isRest"', 'signature_modes', 'x509_fingerprint'], 'id' => $args['id']]);
         if (empty($user)) {
             return [];
         }
diff --git a/src/app/user/models/UserModel.php b/src/app/user/models/UserModel.php
index ab4353310d..42ca5c83f3 100755
--- a/src/app/user/models/UserModel.php
+++ b/src/app/user/models/UserModel.php
@@ -80,7 +80,7 @@ class UserModel
     public static function create(array $args)
     {
         ValidatorModel::notEmpty($args, ['login', 'email', 'firstname', 'lastname', 'picture']);
-        ValidatorModel::stringType($args, ['login', 'email', 'firstname', 'lastname', 'picture', 'mode', 'signatureModes', 'x509_fingerprint']);
+        ValidatorModel::stringType($args, ['login', 'email', 'firstname', 'lastname', 'phone', 'picture', 'mode', 'signatureModes', 'x509_fingerprint']);
 
         if (empty($args['password'])) {
             $args['password'] = AuthenticationModel::generatePassword();
@@ -96,6 +96,7 @@ class UserModel
                 'password'                      => $args['password'],
                 'firstname'                     => $args['firstname'],
                 'lastname'                      => $args['lastname'],
+                'phone'                         => $args['phone'],
                 '"isRest"'                      => empty($args['isRest']) ? 'false' : 'true',
                 'picture'                       => $args['picture'],
                 'password_modification_date'    => 'CURRENT_TIMESTAMP',
-- 
GitLab