From 158724c9fb5538cd118c02988921f589313380df Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Fri, 20 Nov 2020 15:50:26 +0100 Subject: [PATCH] FEAT #14534 TIME 1:40 improved error messages --- migration/20.10/2010.sql | 3 +++ .../controllers/ListTemplateController.php | 21 +++++++++++-------- .../send-signature-book-action.component.html | 4 ++-- src/lang/lang-en.json | 4 +++- src/lang/lang-fr.json | 5 ++++- .../app/entity/ListTemplateControllerTest.php | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/migration/20.10/2010.sql b/migration/20.10/2010.sql index 25a266f54d8..d58e6e3251d 100755 --- a/migration/20.10/2010.sql +++ b/migration/20.10/2010.sql @@ -352,6 +352,9 @@ SET dest_user = ( WHERE item_mode = 'dest' AND item_type = 'user_id' AND listinstance.res_id = res_letterbox.res_id LIMIT 1 ); +/* VISA CIRCUIT PARAMETERS */ +INSERT INTO parameters (id, description, param_value_int) VALUES ('minimumVisaRole', 'Nombre minimum de viseur dans les circuits de visa (0 pour désactiver)', 0); +INSERT INTO parameters (id, description, param_value_int) VALUES ('maximumSignRole', 'Nombre maximum de signataires dans les circuits de visa (0 pour désactiver)', 0); /* ORDER ON CHRONO */ CREATE OR REPLACE FUNCTION order_alphanum(text) RETURNS text AS $$ diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index e068e23d484..03c0abb2d57 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -129,11 +129,14 @@ class ListTemplateController } $allowedTypes = ['diffusionList', 'visaCircuit', 'opinionCircuit']; - $check = Validator::stringType()->notEmpty()->validate($body['type']) && in_array($body['type'], $allowedTypes); - $check = $check && Validator::arrayType()->notEmpty()->validate($body['items']); - $check = $check && (Validator::stringType()->notEmpty()->validate($body['title']) || Validator::stringType()->notEmpty()->validate($body['description'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad allowed types']); + if (!Validator::stringType()->notEmpty()->validate($body['type']) || !in_array($body['type'], $allowedTypes)) { + return $response->withStatus(400)->withJson(['errors' => 'Body type is empty or not an allowed types']); + } + if (!Validator::arrayType()->notEmpty()->validate($body['items'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body items is empty or not an array']); + } + if (!Validator::stringType()->notEmpty()->validate($body['title'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body title is empty or not a string', 'lang' => 'templateNameMandatory']); } if (!empty($body['entityId'])) { @@ -151,7 +154,7 @@ class ListTemplateController $control = ListTemplateController::controlItems(['items' => $body['items'], 'type' => $body['type'], 'entityId' => $body['entityId']]); if (!empty($control['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $control['errors']]); + return $response->withStatus(400)->withJson(['errors' => $control['errors'], 'lang' => $control['lang']]); } $listTemplateId = ListTemplateModel::create([ @@ -217,7 +220,7 @@ class ListTemplateController $control = ListTemplateController::controlItems(['items' => $body['items'], 'type' => $listTemplate['type'], 'entityId' => $listTemplate['entity_id']]); if (!empty($control['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $control['errors']]); + return $response->withStatus(400)->withJson(['errors' => $control['errors'], 'lang' => $control['lang']]); } ListTemplateModel::update([ @@ -691,10 +694,10 @@ class ListTemplateController if ($args['type'] == 'visaCircuit') { if ($minimumVisaRole != 0 && $nbVisaRole < $minimumVisaRole) { - return ['errors' => 'Template does not have enough visa users']; + return ['errors' => 'Template does not have enough visa users', 'lang' => 'notEnoughVisaUser']; } if ($maximumSignRole != 0 && $nbSignRole > $maximumSignRole) { - return ['errors' => 'Template have too many sign users']; + return ['errors' => 'Template have too many sign users', 'lang' => 'tooManySignUser']; } } diff --git a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html index ae0295e7c6d..b563b4fe451 100755 --- a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html +++ b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html @@ -21,10 +21,10 @@ </div> <div *ngIf="!visaNumberCorrect || !signNumberCorrect" class="alert-message alert-message-danger" role="alert"> <p *ngIf="!visaNumberCorrect"> - {{'lang.notEnoughVisaUser' | translate}} + {{'lang.notEnoughVisaUser' | translate}} ({{'lang.requiredVisaUser' | translate: {min: minimumVisaRole} }}) </p> <p *ngIf="!signNumberCorrect"> - {{'lang.tooManySignUser' | translate}} + {{'lang.tooManySignUser' | translate}} ({{'lang.authorizedSignUser' | translate: {max: maximumSignRole} }}) </p> </div> <div *ngIf="resourcesError.length > 0" class="alert-message alert-message-danger mailList" role="alert"> diff --git a/src/lang/lang-en.json b/src/lang/lang-en.json index 406b6ef14a9..76500c362fa 100644 --- a/src/lang/lang-en.json +++ b/src/lang/lang-en.json @@ -2170,5 +2170,7 @@ "noPreviousValid": "No valid previous user", "youCannotUnsign": "You do not have the right to <b>unsign</b> this document. You must be the person who signed this document.", "notEnoughVisaUser": "Not enough approvers", - "tooManySignUser": "Too many signatories" + "tooManySignUser": "Too many signatories", + "requiredVisaUser": "{{min}} approvers required", + "authorizedSignUser": "{{max}} signatories authorized" } diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json index 068b0a68207..264b5837981 100644 --- a/src/lang/lang-fr.json +++ b/src/lang/lang-fr.json @@ -2162,5 +2162,8 @@ "noPreviousValid": "Aucun utilisateur précédent valide", "youCannotUnsign" : "Vous n'avez pas le droit de <b>dé-signer</b> ce document. Vous devez être la personne qui a signé ce document.", "notEnoughVisaUser": "Nombre de viseur insuffisant", - "tooManySignUser": "Nombre de signataire maximum dépassé" + "tooManySignUser": "Nombre de signataire maximum dépassé", + "templateNameMandatory": "Nom du modèle obligatoire", + "requiredVisaUser": "{{min}} viseur(s) requis", + "authorizedSignUser": "{{max}} signataire(s) autorisé(s)" } diff --git a/test/unitTests/app/entity/ListTemplateControllerTest.php b/test/unitTests/app/entity/ListTemplateControllerTest.php index e68f7cec46d..a1e37ee47e2 100755 --- a/test/unitTests/app/entity/ListTemplateControllerTest.php +++ b/test/unitTests/app/entity/ListTemplateControllerTest.php @@ -126,7 +126,7 @@ class ListTemplateControllerTest extends TestCase $response = $listTemplateController->create($fullRequest, new \Slim\Http\Response()); $this->assertSame(400, $response->getStatusCode()); $responseBody = json_decode((string)$response->getBody(), true); - $this->assertSame('Bad allowed types', $responseBody['errors']); + $this->assertSame('Body type is empty or not an allowed types', $responseBody['errors']); $body = [ 'type' => 'diffusionList', -- GitLab