From cfdddf11673fdb15f2d8290ae4ea1afc131a619e Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 10 Jan 2019 16:50:06 +0100
Subject: [PATCH] FEAT #8489 add return errors sendmail test

---
 .../sendmail-administration.component.html    | 22 +++++----
 .../sendmail-administration.component.scss    | 17 ++++++-
 .../sendmail-administration.component.ts      | 48 +++++++++++++------
 src/frontend/lang/lang-en.ts                  |  2 +
 src/frontend/lang/lang-fr.ts                  |  2 +
 src/frontend/lang/lang-nl.ts                  |  2 +
 6 files changed, 67 insertions(+), 26 deletions(-)

diff --git a/src/frontend/app/administration/sendmail/sendmail-administration.component.html b/src/frontend/app/administration/sendmail/sendmail-administration.component.html
index 6ef8191613c..6978ab74066 100644
--- a/src/frontend/app/administration/sendmail/sendmail-administration.component.html
+++ b/src/frontend/app/administration/sendmail/sendmail-administration.component.html
@@ -38,8 +38,8 @@
                             <div class="form-group" [style.opacity]="sendmail.type != 'smtp' ? '0.5' : '1'">
                                 <div class="col-md-2">
                                     <mat-form-field>
-                                        <mat-select name="SMTPSecure" placeholder="{{lang.smtpAuth}}"
-                                            [disabled]="sendmail.type != 'smtp'" [(ngModel)]="sendmail.secure" required>
+                                        <mat-select name="SMTPSecure" placeholder="{{lang.smtpAuth}}" [disabled]="sendmail.type != 'smtp'"
+                                            [(ngModel)]="sendmail.secure" required>
                                             <mat-option *ngFor="let security of smtpSecList" [value]="security">
                                                 {{security}}
                                             </mat-option>
@@ -48,8 +48,8 @@
                                 </div>
                                 <div class="col-md-9">
                                     <mat-form-field>
-                                        <input matInput name="host" [disabled]="sendmail.type != 'smtp'"
-                                            [(ngModel)]="sendmail.host" placeholder="{{lang.host}}" required>
+                                        <input matInput name="host" [disabled]="sendmail.type != 'smtp'" [(ngModel)]="sendmail.host"
+                                            placeholder="{{lang.host}}" required>
                                     </mat-form-field>
                                 </div>
                                 <div class="col-md-1">
@@ -75,8 +75,7 @@
                                 <div class="col-md-12">
                                     <mat-form-field>
                                         <input name="password" [type]="hidePassword ? 'password' : 'text'" [(ngModel)]="sendmail.password"
-                                            [disabled]="!sendmail.auth || sendmail.type != 'smtp'" matInput
-                                            placeholder="{{lang.password}}" required>
+                                            [disabled]="!sendmail.auth || sendmail.type != 'smtp'" matInput placeholder="{{passwordLabel}}">
                                         <mat-icon color="primary" style="cursor: pointer;" matSuffix (click)="hidePassword = !hidePassword"
                                             class="fa fa-2x" [ngClass]="[hidePassword ? 'fa-eye-slash' : 'fa-eye']"></mat-icon>
                                     </mat-form-field>
@@ -103,22 +102,25 @@
         <mat-sidenav #snav2 [mode]="mobileQuery.matches ? 'over' : 'side'" [fixedInViewport]="mobileQuery.matches"
             fixedTopGap="56" position='end' [opened]="mobileQuery.matches ? false : false" style="overflow-x:hidden;width:500px;"
             (opened)="onSubmit();initEmailSend()">
-            <mat-nav-list disableRipple="true">
+            <mat-nav-list disableRipple="true" style="display: flex;flex-direction: column;">
                 <h3 mat-subheader>{{lang.emailSendTest}}</h3>
                 <div class="form-group" [style.opacity]="sendmail.type != 'smtp' ? '0.5' : '1'">
                     <div class="col-md-12">
                         <mat-form-field>
                             <input matInput placeholder="{{lang.mailTo}}" [(ngModel)]="recipientTest" [disabled]="emailSendLoading">
-                            <mat-icon *ngIf="!emailSendLoading" title="{{lang.beginSendTest}}" (click)="testEmailSend()" color="primary" style="cursor: pointer;" matSuffix
-                                class="fa fa-paper-plane fa-2x"></mat-icon>
+                            <mat-icon *ngIf="!emailSendLoading" title="{{lang.beginSendTest}}" (click)="testEmailSend()"
+                                color="primary" style="cursor: pointer;" matSuffix class="fa fa-paper-plane fa-2x"></mat-icon>
                         </mat-form-field>
                     </div>
                 </div>
                 <mat-list-item *ngIf="emailSendResult.msg != ''">
-                    <mat-icon mat-list-icon class= "fas {{emailSendResult.icon}} fa-2x"></mat-icon>
+                    <mat-icon mat-list-icon class="fas {{emailSendResult.icon}} fa-2x"></mat-icon>
                     <p mat-line> {{emailSendResult.msg}} </p>
                 </mat-list-item>
             </mat-nav-list>
+            <div class="bash" *ngIf="this.emailSendResult.msg === lang.emailSendFailed">
+                {{this.emailSendResult.debug}}
+            </div>
         </mat-sidenav>
     </mat-sidenav-container>
 </div>
\ No newline at end of file
diff --git a/src/frontend/app/administration/sendmail/sendmail-administration.component.scss b/src/frontend/app/administration/sendmail/sendmail-administration.component.scss
index 5cfcf4c8c61..3a58dfdfa9f 100644
--- a/src/frontend/app/administration/sendmail/sendmail-administration.component.scss
+++ b/src/frontend/app/administration/sendmail/sendmail-administration.component.scss
@@ -8,4 +8,19 @@
 
 .primary {
     color : #135f7f;
-}
\ No newline at end of file
+}
+
+.red {
+    color: red;
+}
+
+.bash {
+    background : #34495e; 
+    height : 310px ; 
+    border-radius : 5px ;
+    top: 40px;
+    display : absolute; 
+    color : #fff ;
+    padding: 10px;
+    margin: 10px;
+  }
\ No newline at end of file
diff --git a/src/frontend/app/administration/sendmail/sendmail-administration.component.ts b/src/frontend/app/administration/sendmail/sendmail-administration.component.ts
index 90304f79d23..f4014c844a5 100644
--- a/src/frontend/app/administration/sendmail/sendmail-administration.component.ts
+++ b/src/frontend/app/administration/sendmail/sendmail-administration.component.ts
@@ -61,11 +61,13 @@ export class SendmailAdministrationComponent implements OnInit {
     serverConnectionLoading: boolean = false;
     emailSendLoading: boolean = false;
     emailSendResult = {
-        icon : '',
-        msg : ''
+        icon: '',
+        msg: '',
+        debug : ''
     };
     currentUser: any = {};
     recipientTest: string = '';
+    passwordLabel: string = '';
 
 
 
@@ -89,6 +91,12 @@ export class SendmailAdministrationComponent implements OnInit {
                 this.sendmail = data.configuration.value
                 this.sendmailClone = JSON.parse(JSON.stringify(this.sendmail));
                 this.smtpTypeDesc = this.lang[this.sendmail.type + 'Desc'];
+                if (this.sendmail.passwordAlreadyExists === true) {
+                    this.passwordLabel = this.lang.passwordModification;
+                } else {
+                    this.passwordLabel = this.lang.password;
+                }
+                
                 this.loading = false;
             }, (err) => {
                 this.notify.handleErrors(err);
@@ -119,29 +127,31 @@ export class SendmailAdministrationComponent implements OnInit {
 
     initEmailSend() {
         this.emailSendResult = {
-            icon : '',
-            msg : ''
+            icon: '',
+            msg: '',
+            debug: '',
         };
         if (this.currentUser.mail === undefined) {
             this.http.get('../../rest/currentUser/profile')
-            .subscribe((data: any) => {
-                this.currentUser = data;
-                this.recipientTest = data.mail;
-            });
-        }  
+                .subscribe((data: any) => {
+                    this.currentUser = data;
+                    this.recipientTest = data.mail;
+                });
+        }
     }
 
     testEmailSend() {
         this.emailSendResult = {
-            icon : 'fa-paper-plane primary',
-            msg : this.lang.emailSendInProgress
+            icon: 'fa-paper-plane primary',
+            msg: this.lang.emailSendInProgress,
+            debug: ''
         };
         let email = {
             "sender": { "email": this.currentUser.mail },
             "recipients": [this.recipientTest],
-            "object": "test mail envoi",
+            "object": "[" + this.lang.doNotReply +"] " + this.lang.emailSendTest,
             "status": "SENDMAILTEST",
-            "body": "test mail envoi",
+            "body": this.lang.emailSendTest,
             "isHtml": false
         }
         this.emailSendLoading = true;
@@ -150,8 +160,16 @@ export class SendmailAdministrationComponent implements OnInit {
             .subscribe((data: any) => {
                 this.emailSendLoading = false;
                 this.emailSendResult = {
-                    icon : 'fa-check green',
-                    msg : this.lang.emailSendSuccess
+                    icon: 'fa-check green',
+                    msg: this.lang.emailSendSuccess,
+                    debug: ''
+                };
+            }, (err) => {
+                this.emailSendLoading = false;
+                this.emailSendResult = {
+                    icon: 'fa-times red',
+                    msg: this.lang.emailSendFailed,
+                    debug: err.error.errors
                 };
             });
     }
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index 3b981745b63..5eecdd943be 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -740,4 +740,6 @@ export const LANG_EN = {
     "emailSendSuccess"                                  : "Email sent",
     "emailSendInProgress"                               : "Sending email...",
     "smtpAuth"                                          : "Authentication methode",
+    "emailSendFailed"                                   : "Email send failed",
+    "doNotReply"                                        : "Do not reply",
 };
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index f3731aa844f..ce26afbe10b 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -766,6 +766,8 @@ export const LANG_FR = {
     "emailSendSuccess"                                  : "Envoi réussi",
     "emailSendInProgress"                               : "En cours d'envoi...",
     "smtpAuth"                                          : "Méthode d'authentification",
+    "emailSendFailed"                                   : "Échec d'envoi",
+    "doNotReply"                                        : "Ne pas répondre",
 };
 
 
diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts
index 3d6de2e89e6..700168f4175 100755
--- a/src/frontend/lang/lang-nl.ts
+++ b/src/frontend/lang/lang-nl.ts
@@ -769,4 +769,6 @@ export const LANG_NL = {
     "emailSendInProgress" : "_TO_TRANSLATE",
     "smtpAuth" : "_TO_TRANSLATE",
     "sendmailShort" : "_TO_TRANSLATE",
+    "emailSendFailed" : "_TO_TRANSLATE",
+    "doNotReply" : "_TO_TRANSLATE",
 };
-- 
GitLab