From 95db530de636060a72c9d1f0087cd2d97a3d2aca Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Wed, 28 Aug 2024 16:45:47 +0200 Subject: [PATCH 1/9] forbid downloads before end --- .../esupsignature/entity/Workflow.java | 12 +++++++++++- .../esupsignature/service/SignRequestService.java | 15 ++++++++++----- .../esupsignature/service/WorkflowService.java | 1 + .../js/modules/ui/signrequests/WorkspacePdf.js | 2 +- .../templates/admin/workflows/update.html | 4 ++++ .../user/signrequests/cards/stepscard.html | 2 +- .../templates/user/signrequests/show.html | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java index 271259ba7..bc37f177a 100644 --- a/src/main/java/org/esupportail/esupsignature/entity/Workflow.java +++ b/src/main/java/org/esupportail/esupsignature/entity/Workflow.java @@ -57,7 +57,9 @@ public class Workflow { private Boolean sendAlertToAllRecipients = false; private String documentsSourceUri; - + + private Boolean forbidDownloadsBeforeEnd = true; + @ElementCollection(targetClass = String.class, fetch = FetchType.EAGER) private Set managers = new HashSet<>(); @@ -323,4 +325,12 @@ public String getMessageToDisplay() { public void setMessageToDisplay(String messageToDisplay) { this.messageToDisplay = messageToDisplay; } + + public Boolean getForbidDownloadsBeforeEnd() { + return forbidDownloadsBeforeEnd; + } + + public void setForbidDownloadsBeforeEnd(Boolean forbidDownloadsBeforeEnd) { + this.forbidDownloadsBeforeEnd = forbidDownloadsBeforeEnd; + } } diff --git a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java index 0efcdb6b5..b9dc9ea3f 100644 --- a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java +++ b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java @@ -10,16 +10,14 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; import org.esupportail.esupsignature.config.GlobalProperties; import org.esupportail.esupsignature.dss.service.FOPService; import org.esupportail.esupsignature.dto.RecipientWsDto; import org.esupportail.esupsignature.dto.js.JsMessage; import org.esupportail.esupsignature.entity.*; import org.esupportail.esupsignature.entity.enums.*; -import org.esupportail.esupsignature.exception.EsupSignatureFsException; -import org.esupportail.esupsignature.exception.EsupSignatureIOException; -import org.esupportail.esupsignature.exception.EsupSignatureMailException; -import org.esupportail.esupsignature.exception.EsupSignatureRuntimeException; +import org.esupportail.esupsignature.exception.*; import org.esupportail.esupsignature.repository.SignBookRepository; import org.esupportail.esupsignature.repository.SignRequestRepository; import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactoryService; @@ -899,8 +897,11 @@ public boolean getAttachmentResponse(Long signRequestId, Long attachementId, Htt } @Transactional - public void getToSignFileResponse(Long signRequestId, String disposition, HttpServletResponse httpServletResponse) throws IOException, EsupSignatureRuntimeException { + public void getToSignFileResponse(Long signRequestId, String disposition, HttpServletResponse httpServletResponse) throws IOException, EsupSignatureRuntimeException, EsupSignatureException { SignRequest signRequest = getById(signRequestId); + if(disposition.equals("attachment") && signRequest.getParentSignBook().getLiveWorkflow().getWorkflow() != null && BooleanUtils.isTrue(signRequest.getParentSignBook().getLiveWorkflow().getWorkflow().getForbidDownloadsBeforeEnd()) && !signRequest.getStatus().equals(SignRequestStatus.completed)) { + throw new EsupSignatureException("Téléchargement interdit avant la fin du circuit"); + } if (!signRequest.getStatus().equals(SignRequestStatus.exported)) { List documents = signService.getToSignDocuments(signRequest.getId()); Document document; @@ -996,6 +997,10 @@ public byte[] getZipWithDocAndReport(SignRequest signRequest, HttpServletRequest @Transactional public void getFileResponse(Long documentId, HttpServletResponse httpServletResponse) throws IOException { Document document = documentService.getById(documentId); + SignRequest signRequest = getById(document.getParentId()); + if(signRequest.getParentSignBook().getLiveWorkflow().getWorkflow() != null && BooleanUtils.isTrue(signRequest.getParentSignBook().getLiveWorkflow().getWorkflow().getForbidDownloadsBeforeEnd()) && !signRequest.getStatus().equals(SignRequestStatus.completed)) { + throw new EsupSignatureRuntimeException("Téléchargement interdit avant la fin du circuit"); + } webUtilsService.copyFileStreamToHttpResponse(document.getFileName(), document.getContentType(), "attachment", document.getInputStream(), httpServletResponse); } diff --git a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java index 453cfe6dd..b072eb35c 100644 --- a/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java +++ b/src/main/java/org/esupportail/esupsignature/service/WorkflowService.java @@ -492,6 +492,7 @@ public Workflow update(Workflow workflow, User user, String[] types, Set workflowToUpdate.setSealAtEnd(workflow.getSealAtEnd()); workflowToUpdate.setOwnerSystem(workflow.getOwnerSystem()); workflowToUpdate.setDisableDeleteByCreator(workflow.getDisableDeleteByCreator()); + workflowToUpdate.setForbidDownloadsBeforeEnd(workflow.getForbidDownloadsBeforeEnd()); workflowToUpdate.setScanPdfMetadatas(workflow.getScanPdfMetadatas()); workflowToUpdate.setSendAlertToAllRecipients(workflow.getSendAlertToAllRecipients()); workflowToUpdate.getRoles().clear(); diff --git a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js index 673412830..23f4e9996 100644 --- a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js +++ b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js @@ -47,7 +47,7 @@ export class WorkspacePdf { if(currentSignType === "form") { this.pdfViewer = new PdfViewer('/admin/forms/get-file/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, true); } else { - this.pdfViewer = new PdfViewer('/ws-secure/global/get-last-file/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, false); + this.pdfViewer = new PdfViewer('/ws-secure/global/get-last-file-inline/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, false); } } this.signPosition = new SignPosition( diff --git a/src/main/resources/templates/admin/workflows/update.html b/src/main/resources/templates/admin/workflows/update.html index e4b82f2c9..09004bb77 100644 --- a/src/main/resources/templates/admin/workflows/update.html +++ b/src/main/resources/templates/admin/workflows/update.html @@ -155,6 +155,10 @@

WORKFLOW ID : +
+ + +
diff --git a/src/main/resources/templates/user/signrequests/cards/stepscard.html b/src/main/resources/templates/user/signrequests/cards/stepscard.html index 33863fb9d..872c9af2d 100644 --- a/src/main/resources/templates/user/signrequests/cards/stepscard.html +++ b/src/main/resources/templates/user/signrequests/cards/stepscard.html @@ -75,7 +75,7 @@ diff --git a/src/main/resources/templates/user/signrequests/show.html b/src/main/resources/templates/user/signrequests/show.html index 9408ffb3e..02b963d7c 100644 --- a/src/main/resources/templates/user/signrequests/show.html +++ b/src/main/resources/templates/user/signrequests/show.html @@ -97,7 +97,7 @@ -
  • +
  • From 2565284aa7150664922cf5277a739063c2e25e23 Mon Sep 17 00:00:00 2001 From: David Lemaignent Date: Thu, 29 Aug 2024 16:18:45 +0200 Subject: [PATCH 2/9] disable print on with forbidDownloadsBeforeEnd = true --- .../esupsignature/service/SignRequestService.java | 2 +- .../web/wssecure/GlobalWsSecureController.java | 12 ++++++++++++ .../js/modules/ui/signrequests/WorkspacePdf.js | 2 +- .../templates/user/signrequests/includes/tools.html | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java index b9dc9ea3f..bc183921c 100644 --- a/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java +++ b/src/main/java/org/esupportail/esupsignature/service/SignRequestService.java @@ -899,7 +899,7 @@ public boolean getAttachmentResponse(Long signRequestId, Long attachementId, Htt @Transactional public void getToSignFileResponse(Long signRequestId, String disposition, HttpServletResponse httpServletResponse) throws IOException, EsupSignatureRuntimeException, EsupSignatureException { SignRequest signRequest = getById(signRequestId); - if(disposition.equals("attachment") && signRequest.getParentSignBook().getLiveWorkflow().getWorkflow() != null && BooleanUtils.isTrue(signRequest.getParentSignBook().getLiveWorkflow().getWorkflow().getForbidDownloadsBeforeEnd()) && !signRequest.getStatus().equals(SignRequestStatus.completed)) { + if(!disposition.equals("form-data") && signRequest.getParentSignBook().getLiveWorkflow().getWorkflow() != null && BooleanUtils.isTrue(signRequest.getParentSignBook().getLiveWorkflow().getWorkflow().getForbidDownloadsBeforeEnd()) && !signRequest.getStatus().equals(SignRequestStatus.completed)) { throw new EsupSignatureException("Téléchargement interdit avant la fin du circuit"); } if (!signRequest.getStatus().equals(SignRequestStatus.exported)) { diff --git a/src/main/java/org/esupportail/esupsignature/web/wssecure/GlobalWsSecureController.java b/src/main/java/org/esupportail/esupsignature/web/wssecure/GlobalWsSecureController.java index 20cbe42a3..70e4d52ee 100644 --- a/src/main/java/org/esupportail/esupsignature/web/wssecure/GlobalWsSecureController.java +++ b/src/main/java/org/esupportail/esupsignature/web/wssecure/GlobalWsSecureController.java @@ -130,6 +130,18 @@ public ResponseEntity getLastFileFromSignRequestInLine(@ModelAttribute("us return ResponseEntity.internalServerError().build(); } + @PreAuthorize("@preAuthorizeService.signRequestView(#id, #userEppn, #authUserEppn)") + @GetMapping(value = "/get-last-file-pdf/{id}") + public ResponseEntity getLastFileFromSignRequestPdf(@ModelAttribute("userEppn") String userEppn, @ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, HttpServletResponse httpServletResponse) { + try { + signRequestService.getToSignFileResponse(id, "form-data", httpServletResponse); + return ResponseEntity.ok().build(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return ResponseEntity.internalServerError().build(); + } + @PreAuthorize("@preAuthorizeService.signRequestView(#id, #userEppn, #authUserEppn)") @GetMapping(value = "/get-last-file-report/{id}") public ResponseEntity getLastFileReport(@ModelAttribute("userEppn") String userEppn, @ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { diff --git a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js index 23f4e9996..d14769400 100644 --- a/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js +++ b/src/main/resources/static/js/modules/ui/signrequests/WorkspacePdf.js @@ -47,7 +47,7 @@ export class WorkspacePdf { if(currentSignType === "form") { this.pdfViewer = new PdfViewer('/admin/forms/get-file/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, true); } else { - this.pdfViewer = new PdfViewer('/ws-secure/global/get-last-file-inline/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, false); + this.pdfViewer = new PdfViewer('/ws-secure/global/get-last-file-pdf/' + id, signable, editable, currentStepNumber, this.forcePageNum, fields, false); } } this.signPosition = new SignPosition( diff --git a/src/main/resources/templates/user/signrequests/includes/tools.html b/src/main/resources/templates/user/signrequests/includes/tools.html index 039fbcd4f..35e45ea38 100644 --- a/src/main/resources/templates/user/signrequests/includes/tools.html +++ b/src/main/resources/templates/user/signrequests/includes/tools.html @@ -6,7 +6,8 @@ -