diff --git a/rest/index.php b/rest/index.php index e86b28599777f8a701cf8117d43f8716c27c724b..e7a7aba82d1917ca6dde0491ad0684e3594ddada 100755 --- a/rest/index.php +++ b/rest/index.php @@ -403,6 +403,7 @@ $app->get('/administration/templates/new', \Template\controllers\TemplateControl //Users $app->get('/users', \User\controllers\UserController::class . ':get'); $app->post('/users', \User\controllers\UserController::class . ':create'); +$app->get('/users/{id}', \User\controllers\UserController::class . ':getById'); $app->put('/users/{id}', \User\controllers\UserController::class . ':update'); $app->delete('/users/{id}', \User\controllers\UserController::class . ':delete'); $app->put('/users/{id}/suspend', \User\controllers\UserController::class . ':suspend'); diff --git a/sql/structure.sql b/sql/structure.sql index 3b9596dbadafb7bd1de3c15fece0bfa63ff4251a..7ff189a4a417064162b7cf92ed14aec4bc0c4f87 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -825,6 +825,7 @@ CREATE TABLE contacts creation_date TIMESTAMP without time zone NOT NULL DEFAULT NOW(), modification_date TIMESTAMP without time zone, enabled boolean NOT NULL DEFAULT TRUE, + custom_fields jsonb, external_id jsonb DEFAULT '{}', CONSTRAINT contacts_pkey PRIMARY KEY (id) ) diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php index c0c00f35004168c2a8dc6bd51d1736f00d1ba170..812ad24beb3f11edd733b0ef39030b37eaffd38b 100755 --- a/src/app/contact/controllers/ContactController.php +++ b/src/app/contact/controllers/ContactController.php @@ -733,7 +733,7 @@ class ContactController } elseif (!empty($body['phone']) && !preg_match("/\+?((|\ |\.|\(|\)|\-)?(\d)*)*\d$/", $body['phone'])) { return ['errors' => 'Body phone is not valid']; } - + $lengthFields = [ 'civility', 'firstname', @@ -766,6 +766,38 @@ class ContactController } } + $mappingFields = [ + 'civility' => 'civility', + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'company' => 'company', + 'department' => 'department', + 'function' => 'function', + 'address_number' => 'addressNumber', + 'address_street' => 'addressStreet', + 'address_additional1' => 'addressAdditional1', + 'address_additional2' => 'addressAdditional2', + 'address_postcode' => 'addressPostcode', + 'address_town' => 'addressTown', + 'address_country' => 'addressCountry', + 'email' => 'email', + 'phone' => 'phone', + 'notes' => 'notes' + ]; + $mandatoryParameters = ContactParameterModel::get(['select' => ['identifier'], 'where' => ['mandatory = ?'], 'data' => [true]]); + foreach ($mandatoryParameters as $mandatoryParameter) { + if (strpos($mandatoryParameter['identifier'], 'contactCustomField_') !== false) { + $customId = explode('_', $mandatoryParameter['identifier'])[1]; + if (empty($body['customFields'][$customId])) { + return ['errors' => "Body {$body['customFields'][$customId]} is mandatory"]; + } + } else { + if (empty($body[$mappingFields[$mandatoryParameter]])) { + return ['errors' => "Body {$mappingFields[$mandatoryParameter]} is mandatory"]; + } + } + } + return true; } diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 1eba563a994aa29b2b0741d35c62ac80c10f1933..002b6f6aadece829a41b513af0d5741d31ac884d 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -96,6 +96,16 @@ class UserController return $response->withJson(['users' => $users, 'quota' => $quota]); } + public function getById(Request $request, Response $response, array $args) + { + $user = UserModel::getById(['id' => $args['id'], 'select' => ['id', 'firstname', 'lastname']]); + if (empty($user)) { + return $response->withStatus(400)->withJson(['errors' => 'User does not exist']); + } + + return $response->withJson($user); + } + public function getDetailledById(Request $request, Response $response, array $aArgs) { $error = $this->hasUsersRights(['id' => $aArgs['id']]);