Skip to content

Commit

Permalink
Merge pull request #452 from EsupPortail/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dlemaignent authored Sep 2, 2024
2 parents 88bf517 + 5089da5 commit 709c214
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 193 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>org.esupportail</groupId>
<artifactId>esup-signature</artifactId>
<version>1.29.16-SNAPSHOT</version>
<version>1.29.17-SNAPSHOT</version>
<name>esup-signature</name>
<properties>
<startClass>org.esupportail.esupsignature.EsupSignatureApplication</startClass>
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/org/esupportail/esupsignature/entity/Workflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> managers = new HashSet<>();

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LiveWorkflowStep createLiveWorkflowStep(SignBook signBook, WorkflowStep w
LiveWorkflowStep liveWorkflowStep = new LiveWorkflowStep();
liveWorkflowStep.setWorkflowStep(workflowStep);
liveWorkflowStep.setRepeatable(Objects.requireNonNullElse(step.getRepeatable(), false));
liveWorkflowStep.setMultiSign(Objects.requireNonNullElse(step.getMultiSign(), false));
liveWorkflowStep.setMultiSign(Objects.requireNonNullElse(step.getMultiSign(), true));
liveWorkflowStep.setAutoSign(Objects.requireNonNullElse(step.getAutoSign(), false));
liveWorkflowStep.setAllSignToComplete(Objects.requireNonNullElse(step.getAllSignToComplete(), false));
if(step.getSignType() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,15 +264,18 @@ public StepStatus sign(SignRequest signRequest, String password, String signWith
if(signRequestParamses.isEmpty() && visual) {
throw new EsupSignatureRuntimeException("Il manque une signature !");
}
int nbSign = 0;
if (toSignDocuments.size() == 1 && toSignDocuments.get(0).getContentType().equals("application/pdf") && visual) {
for(SignRequestParams signRequestParams : signRequestParamses) {
signedInputStream = pdfService.stampImage(signedInputStream, signRequest, signRequestParams, 1, signerUser, date, userService.getRoles(userEppn).contains("ROLE_OTP"), false);
if(signRequestParams.getSignImageNumber() < 0) {
if(signRequestParams.getSignImageNumber() < 0 && signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign()) {
signedInputStream = pdfService.stampImage(signedInputStream, signRequest, signRequestParams, 1, signerUser, date, userService.getRoles(userEppn).contains("ROLE_OTP"), false);
lastSignLogs.add(updateStatus(signRequest.getId(), signRequest.getStatus(), "Ajout d'un élément", null, "SUCCESS", signRequestParams.getSignPageNumber(), signRequestParams.getxPos(), signRequestParams.getyPos(), signRequest.getParentSignBook().getLiveWorkflow().getCurrentStepNumber(), userEppn, authUserEppn));
auditTrailService.addAuditStep(signRequest.getToken(), userEppn, "Ajout d'un élément", "Pas de timestamp", date, isViewed, signRequestParams.getSignPageNumber(), signRequestParams.getxPos(), signRequestParams.getyPos());
} else {
} else if(signRequestParams.getSignImageNumber() >= 0 && (signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign() || nbSign == 0)) {
signedInputStream = pdfService.stampImage(signedInputStream, signRequest, signRequestParams, 1, signerUser, date, userService.getRoles(userEppn).contains("ROLE_OTP"), false);
lastSignLogs.add(updateStatus(signRequest.getId(), signRequest.getStatus(), "Apposition de la signature", null, "SUCCESS", signRequestParams.getSignPageNumber(), signRequestParams.getxPos(), signRequestParams.getyPos(), signRequest.getParentSignBook().getLiveWorkflow().getCurrentStepNumber(), userEppn, authUserEppn));
auditTrailService.addAuditStep(signRequest.getToken(), userEppn, "Signature simple", "Pas de timestamp", date, isViewed, signRequestParams.getSignPageNumber(), signRequestParams.getxPos(), signRequestParams.getyPos());
nbSign++;
}
}
} else {
Expand Down Expand Up @@ -899,8 +900,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("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)) {
List<Document> documents = signService.getToSignDocuments(signRequest.getId());
Document document;
Expand Down Expand Up @@ -938,8 +942,11 @@ public void getToSignFileResponseWithCode(Long signRequestId, HttpServletRespons


@Transactional
public void getSignedFileAndReportResponse(Long signRequestId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
public void getSignedFileAndReportResponse(Long signRequestId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, boolean force) throws Exception {
SignRequest signRequest = getById(signRequestId);
if(!force && 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");
}
webUtilsService.copyFileStreamToHttpResponse(signRequest.getTitle() + "-avec_rapport", "application/zip; charset=utf-8", "attachment", new ByteArrayInputStream(getZipWithDocAndReport(signRequest, httpServletRequest, httpServletResponse)), httpServletResponse);
}

Expand Down Expand Up @@ -996,6 +1003,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public Workflow update(Workflow workflow, User user, String[] types, Set<String>
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public ResponseEntity<String> deleteSignBook(@PathVariable Long id,
public ResponseEntity<Void> getLastFileFromSignRequest(@PathVariable("id") Long id,
@ModelAttribute("xApiKey") @Parameter(hidden = true) String xApiKey, HttpServletResponse httpServletResponse) {
try {
signRequestService.getToSignFileResponse(id, "attachment", httpServletResponse);
signRequestService.getToSignFileResponse(id, "form-data", httpServletResponse);
return ResponseEntity.ok().build();
} catch (Exception e) {
logger.error(e.getMessage(), e);
Expand All @@ -237,7 +237,7 @@ public ResponseEntity<Void> getLastFileFromSignRequest(@PathVariable("id") Long
public ResponseEntity<Void> getLastFileAndReport(@PathVariable("id") Long id,
@ModelAttribute("xApiKey") @Parameter(hidden = true) String xApiKey, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
try {
signRequestService.getSignedFileAndReportResponse(id, httpServletRequest, httpServletResponse);
signRequestService.getSignedFileAndReportResponse(id, httpServletRequest, httpServletResponse, true);
return ResponseEntity.ok().build();
} catch (Exception e) {
logger.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,23 @@ public ResponseEntity<Void> getLastFileFromSignRequestInLine(@ModelAttribute("us
return ResponseEntity.internalServerError().build();
}

@PreAuthorize("@preAuthorizeService.signRequestView(#id, #userEppn, #authUserEppn)")
@GetMapping(value = "/get-last-file-pdf/{id}")
public ResponseEntity<Void> 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<Void> getLastFileReport(@ModelAttribute("userEppn") String userEppn, @ModelAttribute("authUserEppn") String authUserEppn, @PathVariable("id") Long id, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
try {
signRequestService.getSignedFileAndReportResponse(id, httpServletRequest, httpServletResponse);
signRequestService.getSignedFileAndReportResponse(id, httpServletRequest, httpServletResponse, false);
return ResponseEntity.ok().build();
} catch (Exception e) {
logger.error("get file error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {EventFactory} from "../../utils/EventFactory.js?version=@version@";

export class SignPosition extends EventFactory {

constructor(signType, currentSignRequestParamses, signImageNumber, signImages, userName, authUserName, signable, forceResetSignPos, isOtp, phone, csrf) {
constructor(signType, currentSignRequestParamses, currentStepMultiSign, signImageNumber, signImages, userName, authUserName, signable, forceResetSignPos, isOtp, phone, csrf) {
super();
console.info("Starting sign positioning tools");
this.userName = userName;
this.authUserName = authUserName;
this.pdf = $("#pdf");
this.signImages = signImages;
this.currentStepMultiSign = currentStepMultiSign;
this.isOtp = isOtp;
this.phone = phone;
this.csrf = csrf;
Expand Down Expand Up @@ -110,6 +111,10 @@ export class SignPosition extends EventFactory {
id = 999999;
this.signRequestParamses.set(id, new SignRequestParams(null, id, this.currentScale, page, this.userName, this.authUserName, false, false, false, false, false, false, false, signImageNumber, this.scrollTop, this.csrf, this.signType));
} else if(signImageNumber >= 0) {
if(this.currentStepMultiSign === false && this.signRequestParamses.size > 0) {
alert("Impossible d'ajouter plusieurs signatures sur cette étape");
return;
}
if(JSON.parse(sessionStorage.getItem("favoriteSignRequestParams")) != null) {
favoriteSignRequestParams = JSON.parse(sessionStorage.getItem("favoriteSignRequestParams"));
if(currentSignRequestParams != null) {
Expand All @@ -119,10 +124,18 @@ export class SignPosition extends EventFactory {
}
this.signRequestParamses.set(id, new SignRequestParams(favoriteSignRequestParams, id, this.currentScale, page, this.userName, this.authUserName, restore, true, this.signType === "visa", this.signType === "certSign" || this.signType === "nexuSign", this.isOtp, this.phone, false, this.signImages, this.scrollTop));
} else {
if(this.currentStepMultiSign === false) {
alert("Impossible d'ajouter des annotations sur cette étape");
return;
}
this.signRequestParamses.set(id, new SignRequestParams(favoriteSignRequestParams, id, this.currentScale, page, this.userName, this.authUserName, false, false, false, this.signType === "certSign" || this.signType === "nexuSign", this.isOtp, this.phone, false, null, this.scrollTop));
}
this.signRequestParamses.get(id).changeSignImage(signImageNumber);
} else {
if(this.currentStepMultiSign === false) {
alert("Impossible d'ajouter des annotations sur cette étape");
return;
}
this.signRequestParamses.set(id, new SignRequestParams(null, id, this.currentScale, page, this.userName, this.authUserName, restore, signImageNumber != null && signImageNumber >= 0, false, this.signType === "certSign" || this.signType === "nexuSign", this.isOtp, this.phone, false, null, this.scrollTop));
}
this.signRequestParamses.get(id).addEventListener("unlock", e => this.lockSigns());
Expand Down Expand Up @@ -157,8 +170,10 @@ export class SignPosition extends EventFactory {

addText(page) {
let signRequestParams = this.addSign(page, false, null);
signRequestParams.turnToText();
signRequestParams.cross.css("background-image", "");
signRequestParams.changeSignSize(null);
if(signRequestParams != null) {
signRequestParams.turnToText();
signRequestParams.cross.css("background-image", "");
signRequestParams.changeSignSize(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SignUi {
this.formId = formId;
this.dataId = dataId;
this.currentSignType = currentSignType;
this.workspace = new WorkspacePdf(isPdf, id, dataId, formId, currentSignRequestParamses, signImageNumber, currentSignType, signable, editable, postits, currentStepNumber, currentStepMultiSign, workflow, signImages, userName, authUserName, currentSignType, fields, stepRepeatable, status, this.csrf, action, notSigned, attachmentAlert, attachmentRequire, isOtp, restore, phone);
this.workspace = new WorkspacePdf(isPdf, id, dataId, formId, currentSignRequestParamses, signImageNumber, currentSignType, signable, editable, postits, currentStepNumber, currentStepMultiSign, workflow, signImages, userName, authUserName, fields, stepRepeatable, status, this.csrf, action, notSigned, attachmentAlert, attachmentRequire, isOtp, restore, phone);
this.signRequestUrlParams = "";
this.signComment = $('#signComment');
this.signModal = $('#signModal');
Expand Down
Loading

0 comments on commit 709c214

Please sign in to comment.