From 73b469cadd584c6b193cdece9b35ebe38a69ab70 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Fri, 6 Mar 2020 14:34:48 +0100
Subject: [PATCH] FEAT #13461 TIME 1:15 Fix hasprivilege + opinion

---
 .../diffusionModel-administration.component.ts  | 17 +++++++++++++++--
 .../app/avis/avis-workflow.component.html       | 10 +++++++---
 .../app/avis/avis-workflow.component.scss       | 11 ++++++++++-
 .../app/avis/avis-workflow.component.ts         |  8 +++++---
 .../app/visa/visa-workflow.component.scss       |  2 +-
 .../app/visa/visa-workflow.component.ts         |  4 ++--
 6 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/src/frontend/app/administration/diffusionModel/diffusionModel-administration.component.ts b/src/frontend/app/administration/diffusionModel/diffusionModel-administration.component.ts
index e8131e28155..13d4a1ae87d 100755
--- a/src/frontend/app/administration/diffusionModel/diffusionModel-administration.component.ts
+++ b/src/frontend/app/administration/diffusionModel/diffusionModel-administration.component.ts
@@ -185,11 +185,24 @@ export class DiffusionModelAdministrationComponent implements OnInit {
         }   
     }
 
+    checkPrivileges(items: any) {
+        var isValid = true;
+
+        items.forEach((item: any) => {
+            if (!item.hasPrivilege) {
+                isValid = false;
+            }
+        });
+        console.log(isValid);
+        console.log(items);
+        return isValid;
+    }
+
     isValidForm() {
         if (this.diffusionModel.type === 'visaCircuit') {
-            return this.appVisaWorkflow !== undefined && this.appVisaWorkflow.getWorkflow().length > 0 && this.diffusionModel.title !== '';
+            return this.appVisaWorkflow !== undefined && this.appVisaWorkflow.getWorkflow().length > 0 && this.diffusionModel.title !== '' && this.checkPrivileges(this.appVisaWorkflow.getWorkflow());
         } else {
-            return this.appAvisWorkflow !== undefined && this.appAvisWorkflow.getWorkflow().length > 0 && this.diffusionModel.title !== '';
+            return this.appAvisWorkflow !== undefined && this.appAvisWorkflow.getWorkflow().length > 0 && this.diffusionModel.title !== '' && this.checkPrivileges(this.appAvisWorkflow.getWorkflow());
         }
     }
 
diff --git a/src/frontend/app/avis/avis-workflow.component.html b/src/frontend/app/avis/avis-workflow.component.html
index 178f1c601f3..71be8a79932 100644
--- a/src/frontend/app/avis/avis-workflow.component.html
+++ b/src/frontend/app/avis/avis-workflow.component.html
@@ -56,6 +56,7 @@
             <mat-icon
                 [ngClass]="{'fa fa-user fa-2x': functions.empty(diffusion.picture),'avatar': !functions.empty(diffusion.picture)}"
                 mat-list-icon color="primary"
+                [class.invalid]="!diffusion.hasPrivilege"
                 [style.background-image]="!functions.empty(diffusion.picture) ? 'url('+diffusion.picture+')' : ''">
             </mat-icon>
             <ng-container *ngIf="!adminMode || diffusion.process_date != null">
@@ -65,10 +66,10 @@
             </ng-container>
             <div mat-line class="workflowLine">
                 <div class="workflowLineContainer">
-                    <div class="workflowLineLabel">
+                    <div class="workflowLineLabel" [class.unauthorized]="!diffusion.hasPrivilege">
                         {{diffusion.labelToDisplay}}
                     </div>
-                    <div class="workflowLineSubLabel">
+                    <div class="workflowLineSubLabel" [class.unauthorized]="!diffusion.hasPrivilege">
                         {{diffusion.item_entity}}
                     </div>
                     <div *ngIf="diffusion.process_date != null" class="workflowLineProcessDate"
@@ -82,6 +83,9 @@
                         <button mat-menu-item *ngFor="let role of availableRoles" (click)="changeRole(role, i)">{{role.label}}</button>
                     </mat-menu>
                 </div>
+                <div *ngIf="!diffusion.hasPrivilege" class="invalid">
+                    {{lang.noPrivileges}}
+                </div>
             </div>
             <button mat-icon-button *ngIf="adminMode && functions.empty(diffusion.process_date)"
                 (click)="deleteItem(i)">
@@ -92,4 +96,4 @@
 </mat-list>
 <div *ngIf="loading" style="display:flex;padding: 10px;">
     <mat-spinner style="margin:auto;"></mat-spinner>
-</div>
\ No newline at end of file
+</div>
diff --git a/src/frontend/app/avis/avis-workflow.component.scss b/src/frontend/app/avis/avis-workflow.component.scss
index 5c622317589..dcaccda3e80 100644
--- a/src/frontend/app/avis/avis-workflow.component.scss
+++ b/src/frontend/app/avis/avis-workflow.component.scss
@@ -139,4 +139,13 @@
 
 .valid {
     color: $accent;
-}
\ No newline at end of file
+}
+
+.invalid {
+    color: $warn;
+}
+
+.unauthorized {
+    color: $warn;
+    text-decoration: line-through;
+}
diff --git a/src/frontend/app/avis/avis-workflow.component.ts b/src/frontend/app/avis/avis-workflow.component.ts
index 5b1d57d12ff..c9204a3b243 100644
--- a/src/frontend/app/avis/avis-workflow.component.ts
+++ b/src/frontend/app/avis/avis-workflow.component.ts
@@ -454,7 +454,8 @@ export class AvisWorkflowComponent implements OnInit {
                     item_mode: 'avis',
                     labelToDisplay: item.label,
                     externalId: !this.functions.empty(item.externalId) ? item.externalId : null,
-                    difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id'
+                    difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id',
+                    hasPrivilege : true
                 });
                 this.searchAvisUser.reset();
                 this.searchAvisUserInput.nativeElement.blur();
@@ -463,14 +464,15 @@ export class AvisWorkflowComponent implements OnInit {
                 this.http.get(`../../rest/listTemplates/${item.id}`).pipe(
                     tap((data: any) => {
                         this.avisWorkflow.items = this.avisWorkflow.items.concat(
-                            data.listTemplate.items.filter((itemTemplate: any) => itemTemplate.hasPrivilege === true).map((itemTemplate: any) => {
+                            data.listTemplate.items.map((itemTemplate: any) => {
                                 return {
                                     item_id: itemTemplate.item_id,
                                     item_type: 'user',
                                     labelToDisplay: itemTemplate.idToDisplay,
                                     item_entity: itemTemplate.descriptionToDisplay,
                                     item_mode: 'avis',
-                                    difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id'
+                                    difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id',
+                                    hasPrivilege : itemTemplate.hasPrivilege
                                 }
                             })
                         );
diff --git a/src/frontend/app/visa/visa-workflow.component.scss b/src/frontend/app/visa/visa-workflow.component.scss
index ed2d1f1e5c4..63603117300 100644
--- a/src/frontend/app/visa/visa-workflow.component.scss
+++ b/src/frontend/app/visa/visa-workflow.component.scss
@@ -167,4 +167,4 @@
 .unauthorized {
     color: $warn;
     text-decoration: line-through;
-}
\ No newline at end of file
+}
diff --git a/src/frontend/app/visa/visa-workflow.component.ts b/src/frontend/app/visa/visa-workflow.component.ts
index 00a09e4f973..15ff1176d9b 100644
--- a/src/frontend/app/visa/visa-workflow.component.ts
+++ b/src/frontend/app/visa/visa-workflow.component.ts
@@ -463,7 +463,7 @@ export class VisaWorkflowComponent implements OnInit {
                     tap((data: any) => {
                         this.visaWorkflow.items = this.visaWorkflow.items.concat(
     
-                            data.listTemplate.items.filter((itemTemplate: any) => itemTemplate.hasPrivilege === true).map((itemTemplate: any) => {
+                            data.listTemplate.items.map((itemTemplate: any) => {
                                 return {
                                     item_id: itemTemplate.item_id,
                                     item_type: 'user',
@@ -472,7 +472,7 @@ export class VisaWorkflowComponent implements OnInit {
                                     difflist_type: 'VISA_CIRCUIT',
                                     signatory: false,
                                     requested_signature: itemTemplate.item_mode === 'sign',
-                                    hasPrivilege : item.hasPrivilege
+                                    hasPrivilege : itemTemplate.hasPrivilege
                                 }
                             })
                         );
-- 
GitLab