From bc91df05a06f669e7e2169e7a54fce2c29d1118d Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Mon, 16 Nov 2020 09:32:20 +0100
Subject: [PATCH] FEAT #14567 TIME 1:30 fix some issues + revert get sign modes
 + fix state workflow display

---
 angular.json                                  |  1 -
 package.json                                  |  6 +-
 .../user/controllers/SignatureController.php  |  7 ++
 .../controllers/AuthenticationController.php  |  4 +-
 .../administration/group/group.component.html |  2 +-
 .../administration/user/user.component.html   | 10 ++-
 .../app/administration/user/user.component.ts | 17 +---
 src/frontend/app/app.module.ts                |  4 -
 .../models/visa-workflow-models.component.ts  |  6 +-
 .../visa-workflow.component.html              |  5 +-
 .../visa-workflow.component.scss              |  2 +-
 .../visa-workflow/visa-workflow.component.ts  | 11 ---
 src/frontend/app/service/auth.guard.ts        | 90 +++++++------------
 .../app/sidebar/sidebar.component.html        |  2 +-
 14 files changed, 59 insertions(+), 108 deletions(-)

diff --git a/angular.json b/angular.json
index ba76327052..0c2c2f9da9 100755
--- a/angular.json
+++ b/angular.json
@@ -49,7 +49,6 @@
               },
               "./src/frontend/core/styles.scss",
               "./node_modules/@fortawesome/fontawesome-free/css/all.min.css",
-              "./node_modules/ng2-dnd/bundles/style.css",
               "./node_modules/angular2-draggable/css/resizable.min.css"
             ],
             "scripts": [
diff --git a/package.json b/package.json
index 50eca9cf59..44c7653087 100644
--- a/package.json
+++ b/package.json
@@ -23,7 +23,6 @@
   "license": "GPL-3.0",
   "dependencies": {
     "core-js": "3.6.4",
-    "ng2-dnd": "^5.0.2",
     "tslib": "^2.0.0",
     "zone.js": "~0.10.2"
   },
@@ -45,8 +44,6 @@
     "@biesbjerg/ngx-translate-extract": "^6.0.3",
     "@fortawesome/fontawesome-free": "^5.13.0",
     "@ionic/angular": "^5.0.0",
-    "ngx-drag-scroll": "^9.0.0-beta.4",
-    "ngx-extended-pdf-viewer": "^5.0.1",
     "@ngrx/store": "^9.0.0",
     "@ngrx/store-devtools": "^9.0.0",
     "@ngx-translate/core": "^12.1.2",
@@ -63,8 +60,9 @@
     "hammerjs": "^2.0.8",
     "jquery": "^3.4.1",
     "ngx-cookie-service": "^3.0.3",
+    "ngx-drag-scroll": "^9.0.0-beta.4",
+    "ngx-extended-pdf-viewer": "^5.0.1",
     "ngx-pipes": "^2.7.3",
-    "ngx-scroll-event": "^1.0.8",
     "node-sass": "^4.13.1",
     "npm-check-updates": "^4.1.0",
     "rxjs": "^6.5.4",
diff --git a/src/app/user/controllers/SignatureController.php b/src/app/user/controllers/SignatureController.php
index cc5e730d5b..e106a4dc7e 100755
--- a/src/app/user/controllers/SignatureController.php
+++ b/src/app/user/controllers/SignatureController.php
@@ -233,6 +233,13 @@ class SignatureController
         return $response->withStatus(204);
     }
 
+    public function getSignatureModes(Request $request, Response $response)
+    {
+        $modes = CoreConfigModel::getSignatureModes();
+
+        return $response->withJson($modes);
+    }
+
     public static function isValidSignatureMode(array $args)
     {
         ValidatorModel::stringType($args, ['mode']);
diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php
index e91f67f26b..84c4b7c835 100755
--- a/src/core/controllers/AuthenticationController.php
+++ b/src/core/controllers/AuthenticationController.php
@@ -42,13 +42,11 @@ class AuthenticationController
         $encryptKey = CoreConfigModel::getEncryptKey();
         $path = CoreConfigModel::getConfigPath();
         $hashedPath = md5($path);
-        $signatureModes = CoreConfigModel::getSignatureModes();
 
         return $response->withJson([
             'connection'     => $connection,
             'changeKey'      => $encryptKey == 'Security Key Maarch Parapheur #2008',
-            'instanceId'     => $hashedPath,
-            'signatureModes' => $signatureModes
+            'instanceId'     => $hashedPath
         ]);
     }
 
diff --git a/src/frontend/app/administration/group/group.component.html b/src/frontend/app/administration/group/group.component.html
index 8c11735352..e41ead76e1 100644
--- a/src/frontend/app/administration/group/group.component.html
+++ b/src/frontend/app/administration/group/group.component.html
@@ -30,7 +30,7 @@
         <ion-item lines="none" *ngIf="!creationMode">
             <ion-label color="secondary">{{'lang.linkedUsers' | translate}} :</ion-label>
         </ion-item>
-        <ion-card style="height: 400px;">
+        <ion-card *ngIf="!creationMode" style="height: 400px;">
             <ion-list>
                 <ion-item style="display: flex;">
                     <!--<ion-checkbox slot="start"></ion-checkbox>-->
diff --git a/src/frontend/app/administration/user/user.component.html b/src/frontend/app/administration/user/user.component.html
index 811d74994b..01eb0d3387 100644
--- a/src/frontend/app/administration/user/user.component.html
+++ b/src/frontend/app/administration/user/user.component.html
@@ -38,10 +38,12 @@
             <ion-list-header>
                 <ion-label color="secondary">{{'lang.signatureModes' | translate}}</ion-label>
             </ion-list-header>
-            <ion-item *ngFor="let signMode of signatureModes">
-                <ion-label [style.color]="signMode.color">{{'lang.' + signMode.id | translate}}</ion-label>
-                <ion-checkbox slot="start" [checked]="user.signatureModes.indexOf(signMode.id) > -1" (ionChange)="toggleSignMode(signMode, $event.detail.checked)" [disabled]="signMode.id === 'stamp'"></ion-checkbox>
-            </ion-item>
+            <ng-container *ngFor="let signMode of authService.signatureRoles">
+                <ion-item *ngIf="signMode.id !=='visa'">
+                    <ion-label [style.color]="signMode.color">{{'lang.' + signMode.id | translate}}</ion-label>
+                    <ion-checkbox slot="start" [checked]="user.signatureModes.indexOf(signMode.id) > -1" (ionChange)="toggleSignMode(signMode, $event.detail.checked)" [disabled]="signMode.id === 'stamp'"></ion-checkbox>
+                </ion-item>
+            </ng-container>
         </ion-list>
         <ion-item style="align-items: center;" *ngIf="user.isRest">
             <ion-button slot="end" fill="clear" color="primary" (click)="hideNewPassword = !hideNewPassword">
diff --git a/src/frontend/app/administration/user/user.component.ts b/src/frontend/app/administration/user/user.component.ts
index 7663d91afe..2f288d5d04 100644
--- a/src/frontend/app/administration/user/user.component.ts
+++ b/src/frontend/app/administration/user/user.component.ts
@@ -3,12 +3,11 @@ import { SignaturesContentService } from '../../service/signatures.service';
 import { NotificationService } from '../../service/notification.service';
 import { HttpClient, HttpHeaders } from '@angular/common/http';
 import { MatDialog } from '@angular/material/dialog';
-import { map, finalize, catchError, tap } from 'rxjs/operators';
+import { map, finalize } from 'rxjs/operators';
 import { ActivatedRoute, Router } from '@angular/router';
 import { ConfirmComponent } from '../../plugins/confirm.component';
 import { TranslateService } from '@ngx-translate/core';
 import { AuthService } from '../../service/auth.service';
-import { of } from 'rxjs';
 
 
 export interface User {
@@ -42,7 +41,6 @@ export class UserComponent implements OnInit {
         isRest: false,
         signatureModes: ['stamp']
     };
-    signatureModes: any[] = [];
     userClone: User;
     title: string = '';
     hideCurrentPassword: Boolean = true;
@@ -85,7 +83,6 @@ export class UserComponent implements OnInit {
     }
 
     ngOnInit(): void {
-        this.getSignatureModes();
         this.route.params.subscribe((params: any) => {
             if (params['id'] === undefined) {
                 this.creationMode = true;
@@ -122,18 +119,6 @@ export class UserComponent implements OnInit {
         });
     }
 
-    getSignatureModes() {
-        this.http.get('../rest/signatureModes').pipe(
-            tap((data: any) => {
-                this.signatureModes = data;
-            }),
-            catchError((err: any) => {
-                this.notificationService.handleErrors(err);
-                return of(false);
-            })
-        ).subscribe();
-    }
-
     canValidate() {
         if (this.user.isRest && this.passwordRest.newPassword !== '' && (this.handlePassword.error || this.passwordRest.passwordConfirmation !== this.passwordRest.newPassword)) {
             return false;
diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts
index 76e8b22c63..be8877d2b4 100755
--- a/src/frontend/app/app.module.ts
+++ b/src/frontend/app/app.module.ts
@@ -15,9 +15,7 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
 
 import { NgxExtendedPdfViewerModule } from 'ngx-extended-pdf-viewer';
 import { DragScrollModule } from 'ngx-drag-scroll';
-import { ScrollEventModule } from 'ngx-scroll-event';
 import { AngularDraggableModule } from 'angular2-draggable';
-import { DndModule } from 'ng2-dnd';
 import { CookieService } from 'ngx-cookie-service';
 import { NgPipesModule } from 'ngx-pipes';
 import { LatinisePipe } from 'ngx-pipes';
@@ -148,9 +146,7 @@ import { SortPipe } from './plugins/sorting.pipe';
     }),
     SignaturePadModule,
     NgxExtendedPdfViewerModule,
-    ScrollEventModule,
     DragScrollModule,
-    DndModule.forRoot(),
     NgPipesModule,
     AngularDraggableModule,
     AppMaterialModule,
diff --git a/src/frontend/app/document/visa-workflow/models/visa-workflow-models.component.ts b/src/frontend/app/document/visa-workflow/models/visa-workflow-models.component.ts
index 7c23daed0d..919071e483 100644
--- a/src/frontend/app/document/visa-workflow/models/visa-workflow-models.component.ts
+++ b/src/frontend/app/document/visa-workflow/models/visa-workflow-models.component.ts
@@ -140,11 +140,7 @@ export class VisaWorkflowModelsComponent implements OnInit {
                         'role': item.mode === 'visa' ? 'visa' : item.signatureMode,
                         'processDate': null,
                         'current': false,
-                        'modes': [
-                            'visa',
-                            'sign',
-                            'stamp',
-                        ]
+                        'modes': ['visa'].concat(item.userSignatureModes)
                     };
                     return obj;
                 });
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.html b/src/frontend/app/document/visa-workflow/visa-workflow.component.html
index 806201f191..6a259b7ada 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.html
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.html
@@ -59,8 +59,11 @@
                     {{'lang.'+diffusion.mode+'ProcessInfo' | translate}}
                     {{diffusion.processDate}}
                 </p>
-                <h2 [title]="diffusion.userDisplay">{{diffusion.userDisplay}}</h2>
+                <p class="secondary" *ngIf="diffusion.current && diffusion.userId !== authService.user.id">{{'lang.substituteMsg' | translate}}</p>
+                <h2 [title]="diffusion.userDisplay" *ngIf="diffusion.userDisplay !== ''">{{diffusion.userDisplay}}</h2>
+                <h2 [title]="diffusion.userDisplay" class="danger" *ngIf="diffusion.userDisplay === ''">{{'lang.userDeleted' | translate}}</h2>
             </ion-label>
+            <ion-icon *ngIf="!editMode && diffusion.current" color="success" slot="end" name="caret-back-outline"></ion-icon>
             <ion-button *ngIf="editMode" fill="clear" slot="end" shape="round" color="danger" (click)="removeUser(i)">
                 <ion-icon slot="icon-only" name="trash-outline"></ion-icon>
             </ion-button>
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.scss b/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
index d0ffa7ea27..df70b86fbf 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
@@ -44,7 +44,7 @@ ion-select {
 
 .processDate {
     display: flex;
-    justify-content: start;
+    justify-content: flex-start;
     font-size: 12px;
     text-align: right;
     color : var(--ion-color-success);
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
index 279d35af16..3755f009c6 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
@@ -47,17 +47,7 @@ export class VisaWorkflowComponent implements OnInit {
     }
 
     doReorder(ev: CustomEvent<ItemReorderEventDetail>) {
-        // Before complete is called with the items they will remain in the
-        // order before the drag
-        console.log('Before complete', this.visaWorkflow);
-
-        // Finish the reorder and position the item in the DOM based on
-        // where the gesture ended. Update the items variable to the
-        // new order of items
         this.visaWorkflow = ev.detail.complete(this.visaWorkflow);
-
-        // After complete is called the items will be in the new order
-        console.log('After complete', this.visaWorkflow);
     }
 
     drop(event: CdkDragDrop<string[]>) {
@@ -133,7 +123,6 @@ export class VisaWorkflowComponent implements OnInit {
         popover.onDidDismiss()
             .then((result: any) => {
                 if (result.role !== 'backdrop') {
-                    console.log(result.data);
                     this.visaWorkflow = this.visaWorkflow.concat(result.data);
                     this.visaWorkflow.forEach((element: any, index: number) => {
                         this.getAvatarUser(index);
diff --git a/src/frontend/app/service/auth.guard.ts b/src/frontend/app/service/auth.guard.ts
index 744b8e6409..8079339d39 100644
--- a/src/frontend/app/service/auth.guard.ts
+++ b/src/frontend/app/service/auth.guard.ts
@@ -47,6 +47,23 @@ export class AuthGuard implements CanActivate {
                     this.translate.use(this.authService.user.preferences.lang);
                     this.cookieService.set('maarchParapheurLang', this.authService.user.preferences.lang);
 
+                    if (this.authService.signatureRoles.length === 0) {
+                        this.http.get('../rest/signatureModes')
+                            .subscribe((dataModes: any) => {
+                                this.authService.signatureRoles = [{
+                                    'id': 'visa',
+                                    'type': 'visa',
+                                    'color': '#135F7F'
+                                }];
+                                this.authService.signatureRoles = this.authService.signatureRoles.concat(dataModes.map((item: any) => {
+                                    return {
+                                        ...item,
+                                        type: 'sign'
+                                    };
+                                }));
+                            });
+                    }
+
                     if (this.signaturesService.signaturesList.length === 0) {
                         this.http.get('../rest/users/' + this.authService.user.id + '/signatures')
                             .subscribe((dataSign: any) => {
@@ -60,34 +77,6 @@ export class AuthGuard implements CanActivate {
                                 this.authService.user.picture = dataPic.picture;
                             });
                     }
-
-                    this.authService.signatureRoles = [
-                        {
-                            'id': 'rgs_2stars',
-                            'type': 'sign',
-                            'color': '#FF0000'
-                        },
-                        {
-                            'id': 'inca_card',
-                            'type': 'sign',
-                            'color': '#FFA500'
-                        },
-                        {
-                            'id': 'eidas',
-                            'type': 'sign',
-                            'color': '#00FF00'
-                        },
-                        {
-                            'id': 'stamp',
-                            'type': 'sign',
-                            'color': '#808080'
-                        },
-                        {
-                            'id': 'visa',
-                            'type': 'visa',
-                            'color': '#135F7F'
-                        }
-                    ];
                 }
 
                 return true;
@@ -95,34 +84,6 @@ export class AuthGuard implements CanActivate {
                 return this.http.get('../rest/authenticationInformations')
                     .pipe(
                         map((data: any) => {
-                            // FOR TEST
-                            this.authService.signatureRoles = [
-                                {
-                                    'id': 'rgs_2stars',
-                                    'type': 'sign',
-                                    'color': '#FF0000'
-                                },
-                                {
-                                    'id': 'inca_card',
-                                    'type': 'sign',
-                                    'color': '#FFA500'
-                                },
-                                {
-                                    'id': 'eidas',
-                                    'type': 'sign',
-                                    'color': '#00FF00'
-                                },
-                                {
-                                    'id': 'stamp',
-                                    'type': 'sign',
-                                    'color': '#808080'
-                                },
-                                {
-                                    'id': 'visa',
-                                    'type': 'visa',
-                                    'color': '#135F7F'
-                                }
-                            ];
                             this.authService.authMode = data.connection;
                             this.authService.changeKey = data.changeKey;
                             this.localStorage.setAppSession(data.instanceId);
@@ -134,6 +95,23 @@ export class AuthGuard implements CanActivate {
                                 this.translate.use(this.authService.user.preferences.lang);
                                 this.cookieService.set('maarchParapheurLang', this.authService.user.preferences.lang);
 
+                                if (this.authService.signatureRoles.length === 0) {
+                                    this.http.get('../rest/signatureModes')
+                                        .subscribe((dataModes: any) => {
+                                            this.authService.signatureRoles = [{
+                                                'id': 'visa',
+                                                'type': 'visa',
+                                                'color': '#135F7F'
+                                            }];
+                                            this.authService.signatureRoles = this.authService.signatureRoles.concat(dataModes.map((item: any) => {
+                                                return {
+                                                    ...item,
+                                                    type: 'sign'
+                                                };
+                                            }));
+                                        });
+                                }
+
                                 if (this.signaturesService.signaturesList.length === 0) {
                                     this.http.get('../rest/users/' + this.authService.user.id + '/signatures')
                                         .subscribe((dataSign: any) => {
diff --git a/src/frontend/app/sidebar/sidebar.component.html b/src/frontend/app/sidebar/sidebar.component.html
index d921121ec8..718b8a4826 100755
--- a/src/frontend/app/sidebar/sidebar.component.html
+++ b/src/frontend/app/sidebar/sidebar.component.html
@@ -13,7 +13,7 @@
             <ion-button (click)="authService.logout()">
                 <ion-icon slot="icon-only" name="power"></ion-icon>
             </ion-button>
-            <ion-button *ngIf="!isAdminRoute()" (click)="openAdmin()">
+            <ion-button *ngIf="!isAdminRoute() && authService.user.administrativePrivileges.length > 0" (click)="openAdmin()">
                 <ion-icon slot="icon-only" name="build-outline"></ion-icon>
             </ion-button>
             <ion-button *ngIf="isAdminRoute()" (click)="openHome()">
-- 
GitLab