From 01faf3b84b86e8ddb0c74225c5ac0efbe20be847 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 16 Apr 2020 17:55:37 +0200
Subject: [PATCH] FIX #13441 TIME 1:45 disallow java edition in base64

---
 .../template-administration.component.html    |  4 ++--
 .../template-administration.component.ts      | 22 +++++++++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/frontend/app/administration/template/template-administration.component.html b/src/frontend/app/administration/template/template-administration.component.html
index 92a7b2ae35f..3ac98bad58f 100755
--- a/src/frontend/app/administration/template/template-administration.component.html
+++ b/src/frontend/app/administration/template/template-administration.component.html
@@ -149,7 +149,7 @@
                                         [disabled]="lockFound">{{lang.templateEdition}}</button>
                                     <button mat-raised-button color="default" type="button"
                                         (click)="$event.stopPropagation();uploadSignFileOffice.click()"
-                                        *ngIf="((creationMode && !selectedModelFile) || (!creationMode && !functionsService.empty(template.file.name)))"
+                                        *ngIf="((creationMode && !selectedModelFile) || (!creationMode && !functionsService.empty(template.file.name)) && headerService.user.preferences.documentEdition !== 'java')"
                                         [disabled]="lockFound">{{lang.importFile}}</button>
                                 </div>
                                 <iframe *ngIf="templateDocView !== null" [src]="templateDocView"
@@ -248,7 +248,7 @@
                                                 [disabled]="lockFound">{{lang.templateEdition}}</button>
                                             <button mat-raised-button color="default" type="button"
                                                 (click)="$event.stopPropagation();uploadSignFileOfficeHtml.click()"
-                                                *ngIf="!selectedModelFile || !creationMode"
+                                                *ngIf="!selectedModelFile || (!creationMode && headerService.user.preferences.documentEdition !== 'java')"
                                                 [disabled]="lockFound">{{lang.importFile}}</button>
                                         </div>
                                         <iframe *ngIf="templateDocView !== null" [src]="templateDocView"
diff --git a/src/frontend/app/administration/template/template-administration.component.ts b/src/frontend/app/administration/template/template-administration.component.ts
index 9ad36672fb3..af394100356 100755
--- a/src/frontend/app/administration/template/template-administration.component.ts
+++ b/src/frontend/app/administration/template/template-administration.component.ts
@@ -93,7 +93,7 @@ export class TemplateAdministrationComponent implements OnInit, OnDestroy {
         private route: ActivatedRoute,
         private router: Router,
         private notify: NotificationService,
-        private headerService: HeaderService,
+        public headerService: HeaderService,
         public dialog: MatDialog,
         public appService: AppService,
         private viewContainerRef: ViewContainerRef,
@@ -376,6 +376,24 @@ export class TemplateAdministrationComponent implements OnInit, OnDestroy {
         }
 
         if (this.headerService.user.preferences.documentEdition === 'java') {
+            // WORKAROUND JAVA MODE DOESNT SUPPORT BASE64 
+            if (this.creationMode) {
+                editorOptions.objectId = '';
+                editorOptions.objectType = 'templateCreation';
+                for (const element of this.defaultTemplatesList) {
+                    if (this.selectedModelFile === element.fileExt + ': ' + element.fileName) {
+                        editorOptions.objectId = element.filePath;
+                    }
+                }
+                if (this.functionsService.empty(editorOptions.objectId)) {
+                    alert('Vous ne pouvez pas éditer avec l\'applet Java un document importé.');
+                    return false;
+                }
+            } else {
+                editorOptions.objectType = 'templateModification';
+                editorOptions.objectId = this.template.id;
+            }
+
             this.launchJavaEditor(editorOptions);
         } else if (this.headerService.user.preferences.documentEdition === 'onlyoffice') {
             this.launchOOEditor(editorOptions);
@@ -469,7 +487,7 @@ export class TemplateAdministrationComponent implements OnInit, OnDestroy {
                     this.template.file.format = filenameOnTmp.toLowerCase().split('.').pop();
                     this.template.file.content = data.encodedResource;
                 }
-                this.templateDocView = data.encodedConvertedResource;
+                this.templateDocView = this.sanitizer.bypassSecurityTrustResourceUrl('data:application/pdf;base64,' + data.encodedConvertedResource);
             })
         ).subscribe();
     }
-- 
GitLab