From 83f1e4a8ca6f1391e31dbed3c46781fe7a7b342a Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 19 May 2021 17:29:38 +0200
Subject: [PATCH] FEAT #16992 TIME 0:10 Improve controle for yousign
 notification in administration

---
 .../controllers/ExternalSignatoryBookController.php       | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/app/externalSignatoryBook/controllers/ExternalSignatoryBookController.php b/src/app/externalSignatoryBook/controllers/ExternalSignatoryBookController.php
index bde9d82278..6d5953e606 100755
--- a/src/app/externalSignatoryBook/controllers/ExternalSignatoryBookController.php
+++ b/src/app/externalSignatoryBook/controllers/ExternalSignatoryBookController.php
@@ -82,8 +82,6 @@ class ExternalSignatoryBookController
             return $response->withStatus(400)->withJson(['errors' => 'Body type is empty or not a string or longer than 128 caracteres']);
         } elseif (!Validator::arrayType()->notEmpty()->validate($body['securityModes'])) {
             return $response->withStatus(400)->withJson(['errors' => 'Body securityModes is empty or not an array']);
-        } elseif (!empty($body['message']['otp_sms']) && !Validator::stringType()->notEmpty()->length(1, 150)->validate($body['message']['otp_sms'])) {
-            return $response->withStatus(400)->withJson(['errors' => 'Body message otp_sms length must be less than 150 caracteres']);
         }
 
         if ($body['type'] != 'yousign') {
@@ -99,6 +97,12 @@ class ExternalSignatoryBookController
             if (empty($body['apiUri']) || empty($body['apiKey'])) {
                 return $response->withStatus(400)->withJson(['errors' => 'Body apiUri or apiKey is empty']);
             }
+            if (empty($body['message']['notification']['subject']) || empty($body['message']['notification']['body'])) {
+                return $response->withStatus(400)->withJson(['errors' => 'Body message notification must have subject and body attributes']);
+            }
+            if (!empty($body['message']['otp_sms']) && !Validator::stringType()->notEmpty()->length(1, 150)->validate($body['message']['otp_sms'])) {
+                return $response->withStatus(400)->withJson(['errors' => 'Body message otp_sms length must be less than 150 caracteres']);
+            }
             if (in_array('sms', $body['securityModes']) && empty($body['message']['otp_sms'])) {
                 return $response->withStatus(400)->withJson(['errors' => 'Body message otp_sms must be set']);
             }
-- 
GitLab