From 904b390e1adb77d41183c348445be4df38b82c01 Mon Sep 17 00:00:00 2001
From: "hamza.hramchi" <hamza.hramchi@xelians.fr>
Date: Mon, 17 May 2021 14:07:12 +0200
Subject: [PATCH] FEAT #16992 TIME 0:20 admin OTP: add subject and body of
 notification + maxLengh for sms content

---
 lang/fr.json                                     |  3 ++-
 .../app/administration/otp/otp.component.html    |  9 +++++++--
 .../app/administration/otp/otp.component.ts      | 16 ++++++++++++----
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/lang/fr.json b/lang/fr.json
index bbedf423c9..0dadfb69d0 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -497,6 +497,7 @@
 		"connectorUpdated": "Connecteur modifié",
 		"connectorDeleted": "Connecteur supprimé",
 		"smsContent": "Contenu du SMS envoyé",
-		"emailContent": "Contenu du courriel envoyé"
+		"emailContent": "Contenu de la notification à envoyer par courriel",
+		"emailSubject": "Sujet"
 	}
 }
diff --git a/src/frontend/app/administration/otp/otp.component.html b/src/frontend/app/administration/otp/otp.component.html
index 4903668e0c..535cab81ff 100644
--- a/src/frontend/app/administration/otp/otp.component.html
+++ b/src/frontend/app/administration/otp/otp.component.html
@@ -60,12 +60,17 @@
                 </ion-label>
             </ion-list-header>
             <ion-item>
-                <ion-textarea name ="smsContent"rows="2" cols="10" [(ngModel)]="connector.message.sms" 
+                <ion-textarea name ="smsContent"rows="2" cols="10" [maxlength]="150" [(ngModel)]="connector.message.otp_sms" 
                     [required]="connector.securityModes.includes('sms')" placeholder="Ex: Bonjour Alain Dupont, le code de sécurité est ...">
                 </ion-textarea>
             </ion-item>
         </ion-list>
         <ion-list *ngIf="connector.securityModes.includes('email')">
+            <ion-item>
+                <ion-label color="secondary" position="floating">{{ 'lang.emailSubject' | translate}} *</ion-label>
+                <ion-input name="subject" [(ngModel)]="connector.message.notification.subject" required>
+                </ion-input>
+            </ion-item>
             <ion-list-header>
                 <ion-label color="secondary">
                     {{ 'lang.emailContent' | translate}} <ng-container
@@ -73,7 +78,7 @@
                 </ion-label>
             </ion-list-header>
             <ion-item>
-                <ion-textarea name="emailContent" rows="2" cols="10" [(ngModel)]="connector.message.email"
+                <ion-textarea name="emailContent" rows="2" cols="10" [(ngModel)]="connector.message.notification.body"
                     [required]="connector.securityModes.includes('email')" placeholder="Ex: Bonjour Alain Dupont, le code de sécurité est ...">
                 </ion-textarea>
             </ion-item>
diff --git a/src/frontend/app/administration/otp/otp.component.ts b/src/frontend/app/administration/otp/otp.component.ts
index 02683519e9..f6e7839549 100644
--- a/src/frontend/app/administration/otp/otp.component.ts
+++ b/src/frontend/app/administration/otp/otp.component.ts
@@ -69,8 +69,11 @@ export class OtpComponent implements OnInit {
             apiKey: '',
             securityModes: ['sms'],
             message : {
-                sms: '',
-                email: ''
+                otp_sms : '',
+                notification : {
+                    subject: '',
+                    body: ''
+                }
             }
         };
     }
@@ -131,8 +134,6 @@ export class OtpComponent implements OnInit {
     }
 
     onSubmit() {
-        this.connector.message.sms = !this.connector.securityModes.includes('sms') ? '' : this.connector.message.sms;
-        this.connector.message.email = !this.connector.securityModes.includes('email') ? '' : this.connector.message.email;
         if (this.creationMode) {
             this.createconnector();
         } else {
@@ -212,6 +213,13 @@ export class OtpComponent implements OnInit {
         } else {
             const index = this.connector.securityModes.indexOf(ev.value);
             this.connector.securityModes.splice(index, 1);
+            this.connector.message.otp_sms = this.connector.securityModes.indexOf('sms') === -1 ? '' : this.connector.message.sms;
+            if (this.connector.securityModes.indexOf('email') === -1) {
+                this.connector.message.notification = {
+                    subject: '',
+                    body: ''
+                };
+            }
         }
     }
 
-- 
GitLab