Skip to content

Commit

Permalink
Merge pull request #482 from EsupPortail/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dlemaignent authored Jan 24, 2025
2 parents ce28162 + b0823c1 commit 623cd49
Show file tree
Hide file tree
Showing 23 changed files with 134 additions and 38 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -12,7 +13,7 @@
</parent>
<groupId>org.esupportail</groupId>
<artifactId>esup-signature</artifactId>
<version>1.32.2</version>
<version>1.32.3-SNAPSHOT</version>
<name>esup-signature</name>
<properties>
<startClass>org.esupportail.esupsignature.EsupSignatureApplication</startClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class WorkflowStepDto {

private Boolean multiSign = true;

private Boolean singleSignWithAnnotation = false;

private Boolean autoSign = false;

private Boolean forceAllSign = false;
Expand Down Expand Up @@ -182,6 +184,14 @@ public void setMultiSign(Boolean multiSign) {
this.multiSign = multiSign;
}

public Boolean getSingleSignWithAnnotation() {
return singleSignWithAnnotation;
}

public void setSingleSignWithAnnotation(Boolean singleSignWithAnnotation) {
this.singleSignWithAnnotation = singleSignWithAnnotation;
}

public Boolean getAutoSign() {
return autoSign;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Entity
Expand All @@ -33,6 +34,8 @@ public class LiveWorkflowStep {

private Boolean multiSign = true;

private Boolean singleSignWithAnnotation = false;

private Boolean autoSign = false;

@NotNull
Expand Down Expand Up @@ -93,6 +96,14 @@ public void setMultiSign(Boolean multiSign) {
this.multiSign = multiSign;
}

public Boolean getSingleSignWithAnnotation() {
return Objects.requireNonNullElse(singleSignWithAnnotation, false);
}

public void setSingleSignWithAnnotation(Boolean singleSignWithAnnotation) {
this.singleSignWithAnnotation = singleSignWithAnnotation;
}

public Boolean getAutoSign() {
if(autoSign == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import org.hibernate.annotations.FetchMode;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import java.util.*;

@Entity
public class WorkflowStep {
Expand Down Expand Up @@ -44,6 +42,8 @@ public class WorkflowStep {

private Boolean multiSign = true;

private Boolean singleSignWithAnnotation = false;

private Boolean autoSign = false;

@ManyToOne
Expand Down Expand Up @@ -112,6 +112,14 @@ public void setMultiSign(Boolean multiSign) {
this.multiSign = multiSign;
}

public Boolean getSingleSignWithAnnotation() {
return Objects.requireNonNullElse(singleSignWithAnnotation, false);
}

public void setSingleSignWithAnnotation(Boolean singleSignWithAnnotation) {
this.singleSignWithAnnotation = singleSignWithAnnotation;
}

public Boolean getAutoSign() {
if(autoSign == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import eu.europa.esig.dss.token.DSSPrivateKeyEntry;
import eu.europa.esig.dss.token.Pkcs12SignatureToken;
import eu.europa.esig.dss.token.SignatureTokenConnection;
import jakarta.annotation.PostConstruct;
import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.config.sign.SignProperties;
import org.esupportail.esupsignature.entity.Certificat;
Expand Down Expand Up @@ -197,6 +198,7 @@ public CertificateToken getOpenSCKey() throws DSSException {
return null;
}

@PostConstruct
public List<DSSPrivateKeyEntry> getSealCertificats() {
if(privateKeysCache.getIfPresent("keys") != null) return privateKeysCache.getIfPresent("keys");
List<DSSPrivateKeyEntry> dssPrivateKeyEntries = new ArrayList<>();
Expand Down Expand Up @@ -229,7 +231,8 @@ public List<DSSPrivateKeyEntry> getSealCertificats() {
return dssPrivateKeyEntries;
}

public boolean checkCertificatProblem() {
public boolean checkCertificatProblem(List<String> roles) {
if(!roles.contains("ROLE_ADMIN")) return false;
boolean certificatProblem = false;
List<DSSPrivateKeyEntry> dssPrivateKeyEntries = getSealCertificats();
if(isCertificatWasPresent && dssPrivateKeyEntries.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public LiveWorkflowStep createLiveWorkflowStep(SignBook signBook, WorkflowStep w
liveWorkflowStep.setWorkflowStep(workflowStep);
liveWorkflowStep.setRepeatable(Objects.requireNonNullElse(step.getRepeatable(), false));
liveWorkflowStep.setMultiSign(Objects.requireNonNullElse(step.getMultiSign(), true));
liveWorkflowStep.setSingleSignWithAnnotation(Objects.requireNonNullElse(step.getSingleSignWithAnnotation(), false));
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 @@ -268,7 +268,7 @@ public StepStatus sign(SignRequest signRequest, String password, String signWith
int nbSign = 0;
if (toSignDocuments.size() == 1 && toSignDocuments.get(0).getContentType().equals("application/pdf") && visual) {
for(SignRequestParams signRequestParams : signRequestParamses) {
if(signRequestParams.getSignImageNumber() < 0 && signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign()) {
if(signRequestParams.getSignImageNumber() < 0 && (signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign() || signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getSingleSignWithAnnotation())) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,14 @@ public void setWorkflowSetupFromJson(Long id, InputStream inputStream) throws IO
Optional<WorkflowStep> optionalWorkflowStep = workflow.getWorkflowSteps().stream().filter(workflowStep1 -> workflowStep1.getId().equals(workflowStepSetup.getId())).findFirst();
if(optionalWorkflowStep.isPresent()) {
WorkflowStep workflowStep = optionalWorkflowStep.get();
workflowStepService.updateStep(workflowStep.getId(), workflowStepSetup.getSignType(), workflowStepSetup.getDescription(), workflowStepSetup.getChangeable(), workflowStepSetup.getRepeatable(), workflowStepSetup.getMultiSign(), workflowStepSetup.getAllSignToComplete(), workflowStepSetup.getMaxRecipients(), workflowStepSetup.getAttachmentAlert(), workflowStepSetup.getAttachmentRequire(), false, null);
workflowStepService.updateStep(workflowStep.getId(), workflowStepSetup.getSignType(), workflowStepSetup.getDescription(), workflowStepSetup.getChangeable(), workflowStepSetup.getRepeatable(), workflowStepSetup.getMultiSign(), workflowStepSetup.getSingleSignWithAnnotation(), workflowStepSetup.getAllSignToComplete(), workflowStepSetup.getMaxRecipients(), workflowStepSetup.getAttachmentAlert(), workflowStepSetup.getAttachmentRequire(), false, null);
} else {
List<RecipientWsDto> recipients = new ArrayList<>();
for(User user : workflowStepSetup.getUsers()) {
recipients.add(new RecipientWsDto(user.getEmail()));
}
WorkflowStep newWorkflowStep = workflowStepService.createWorkflowStep(workflowSetup.getName(), workflowStepSetup.getAllSignToComplete(), workflowStepSetup.getSignType(), workflowStepSetup.getChangeable(), recipients.toArray(RecipientWsDto[]::new));
workflowStepService.updateStep(newWorkflowStep.getId(), workflowStepSetup.getSignType(), workflowStepSetup.getDescription(), workflowStepSetup.getChangeable(), workflowStepSetup.getRepeatable(), workflowStepSetup.getMultiSign(), workflowStepSetup.getAllSignToComplete(), workflowStepSetup.getMaxRecipients(), workflowStepSetup.getAttachmentAlert(), workflowStepSetup.getAttachmentRequire(), false, null);
workflowStepService.updateStep(newWorkflowStep.getId(), workflowStepSetup.getSignType(), workflowStepSetup.getDescription(), workflowStepSetup.getChangeable(), workflowStepSetup.getRepeatable(), workflowStepSetup.getMultiSign(), workflowStepSetup.getSingleSignWithAnnotation(), workflowStepSetup.getAllSignToComplete(), workflowStepSetup.getMaxRecipients(), workflowStepSetup.getAttachmentAlert(), workflowStepSetup.getAttachmentRequire(), false, null);
workflow.getWorkflowSteps().add(newWorkflowStep);
}
}
Expand Down Expand Up @@ -699,6 +699,7 @@ public void importWorkflow(SignBook signBook, Workflow workflow, List<WorkflowSt
step.setRepeatable(workflowStep.getRepeatable());
step.setRepeatableSignType(workflowStep.getRepeatableSignType());
step.setMultiSign(workflowStep.getMultiSign());
step.setSingleSignWithAnnotation(workflowStep.getSingleSignWithAnnotation());
step.setAutoSign(workflowStep.getAutoSign());
step.setAllSignToComplete(workflowStep.getAllSignToComplete());
step.setSignType(workflowStep.getSignType());
Expand All @@ -710,5 +711,9 @@ public void importWorkflow(SignBook signBook, Workflow workflow, List<WorkflowSt
}
}


@Transactional
public void updateSendAlertToAllRecipients(Long id, Boolean sendAlertToAllRecipients) {
Workflow workflow = getById(id);
workflow.setSendAlertToAllRecipients(sendAlertToAllRecipients);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public WorkflowStep removeStepRecipient(Long workflowStepId, String userEppn) {
}

@Transactional
public void updateStep(Long workflowStepId, SignType signType, String description, Boolean changeable, Boolean repeatable, Boolean multiSign, Boolean allSignToComplete, Integer maxRecipients, Boolean attachmentAlert, Boolean attachmentRequire, Boolean autoSign, Long certificatId) throws EsupSignatureRuntimeException {
public void updateStep(Long workflowStepId, SignType signType, String description, Boolean changeable, Boolean repeatable, Boolean multiSign, Boolean singleSignWithAnnotation, Boolean allSignToComplete, Integer maxRecipients, Boolean attachmentAlert, Boolean attachmentRequire, Boolean autoSign, Long certificatId) throws EsupSignatureRuntimeException {
if(repeatable != null && repeatable && signType.getValue() > 2) {
throw new EsupSignatureRuntimeException(signType.name() + ", type de signature impossible pour une étape infinie");
}
Expand All @@ -129,6 +129,11 @@ public void updateStep(Long workflowStepId, SignType signType, String descriptio
workflowStep.setAttachmentAlert(attachmentAlert);
workflowStep.setAttachmentRequire(attachmentRequire);
workflowStep.setMultiSign(Objects.requireNonNullElse(multiSign, false));
if(workflowStep.getMultiSign()) {
workflowStep.setSingleSignWithAnnotation(true);
} else {
workflowStep.setSingleSignWithAnnotation(Objects.requireNonNullElse(singleSignWithAnnotation, false));
}
workflowStep.setAllSignToComplete(Objects.requireNonNullElse(allSignToComplete, false));
workflowStep.setAutoSign(autoSign);
if(autoSign) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ public void globalAttributes(@ModelAttribute("userEppn") String userEppn, @Model
model.addAttribute("signTypes", signTypeService.getAuthorizedSignTypes(roles));
model.addAttribute("nbSignRequests", signRequestService.getNbPendingSignRequests(userEppn));
model.addAttribute("nbToSign", signBookService.nbToSignSignBooks(userEppn));
model.addAttribute("certificatProblem", certificatService.checkCertificatProblem(roles));
}
model.addAttribute("applicationEmail", globalProperties.getApplicationEmail());
model.addAttribute("maxInactiveInterval", httpSession.getMaxInactiveInterval());
model.addAttribute("certificatProblem", certificatService.checkCertificatProblem());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public String updateStep(@ModelAttribute("authUserEppn") String authUserEppn,
@RequestParam(name="maxRecipients", required = false) Integer maxRecipients,
@RequestParam(name="repeatable", required = false) Boolean repeatable,
@RequestParam(name="multiSign", required = false) Boolean multiSign,
@RequestParam(name="singleSignWithAnnotation", required = false) Boolean singleSignWithAnnotation,
@RequestParam(name="changeable", required = false) Boolean changeable,
@RequestParam(name="allSignToComplete", required = false) Boolean allSignToComplete,
@RequestParam(name="attachmentAlert", required = false) Boolean attachmentAlert,
Expand All @@ -210,7 +211,7 @@ public String updateStep(@ModelAttribute("authUserEppn") String authUserEppn,
RedirectAttributes redirectAttributes) {
Workflow workflow = workflowService.getById(id);
try {
workflowStepService.updateStep(workflow.getWorkflowSteps().get(step).getId(), signType, description, changeable, repeatable, multiSign, allSignToComplete, maxRecipients, attachmentAlert, attachmentRequire, autoSign, certificatId);
workflowStepService.updateStep(workflow.getWorkflowSteps().get(step).getId(), signType, description, changeable, repeatable, multiSign, singleSignWithAnnotation, allSignToComplete, maxRecipients, attachmentAlert, attachmentRequire, autoSign, certificatId);
} catch (EsupSignatureRuntimeException e) {
redirectAttributes.addFlashAttribute("message", new JsMessage("error", e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public String show(@ModelAttribute("userEppn") String userEppn, @ModelAttribute(
if(signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep() != null && signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getWorkflowStep() != null) {
model.addAttribute("currentStepId", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getWorkflowStep().getId());
model.addAttribute("currentStepMultiSign", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign());
model.addAttribute("currentStepSingleSignWithAnnotation", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getSingleSignWithAnnotation());
} else {
model.addAttribute("currentStepMultiSign", true);
model.addAttribute("currentStepSingleSignWithAnnotation", false);
}
model.addAttribute("nbSignRequestInSignBookParent", signRequest.getParentSignBook().getSignRequests().size());
List<Document> toSignDocuments = signService.getToSignDocuments(signRequest.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ public String changeStepSignType(@ModelAttribute("userEppn") String userEppn,
@RequestParam(name="maxRecipients", required = false) Integer maxRecipients,
@RequestParam(name="changeable", required = false) Boolean changeable,
@RequestParam(name="multiSign", required = false) Boolean multiSign,
@RequestParam(name="singleSignWithAnnotation", required = false) Boolean singleSignWithAnnotation,
@RequestParam(name="repeatable", required = false) Boolean repeatable,
@RequestParam(name="allSignToComplete", required = false) Boolean allSignToComplete,
@RequestParam(name="attachmentAlert", required = false) Boolean attachmentAlert,
@RequestParam(name="attachmentRequire", required = false) Boolean attachmentRequire,
RedirectAttributes redirectAttributes) {
Workflow workflow = workflowService.getById(id);
try {
workflowStepService.updateStep(workflow.getWorkflowSteps().get(step).getId(), signType, description, changeable, repeatable, multiSign, allSignToComplete, maxRecipients, attachmentAlert, attachmentRequire, false, null);
workflowStepService.updateStep(workflow.getWorkflowSteps().get(step).getId(), signType, description, changeable, repeatable, multiSign, singleSignWithAnnotation, allSignToComplete, maxRecipients, attachmentAlert, attachmentRequire, false, null);
} catch (EsupSignatureRuntimeException e) {
redirectAttributes.addFlashAttribute("message", new JsMessage("error", "Type de signature impossible pour une étape infinie"));
}
Expand Down Expand Up @@ -140,13 +141,17 @@ public String delete(@ModelAttribute("userEppn") String userEppn, @PathVariable(
return "redirect:/";
}


//add sendAlertToAllRecipients update to workflow
@PutMapping(value = "/{id}")
@PreAuthorize("@preAuthorizeService.workflowOwner(#id, #userEppn)")
public String rename(@ModelAttribute("userEppn") String userEppn, @PathVariable("id") Long id,
@RequestParam(required = false) List<String> viewers,
@RequestParam(required = false) Boolean sendAlertToAllRecipients,
@RequestParam String name) {
workflowService.rename(id, name);
workflowService.addViewers(id, viewers);
workflowService.updateSendAlertToAllRecipients(id, sendAlertToAllRecipients);
return "redirect:/user/workflows/" + id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public String show(@ModelAttribute("userEppn") String userEppn, @ModelAttribute(
if(signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep() != null && signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getWorkflowStep() != null) {
model.addAttribute("currentStepId", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getWorkflowStep().getId());
model.addAttribute("currentStepMultiSign", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getMultiSign());
model.addAttribute("currentStepSingleSignWithAnnotation", signRequest.getParentSignBook().getLiveWorkflow().getCurrentStep().getSingleSignWithAnnotation());
}
model.addAttribute("nbSignRequestInSignBookParent", signRequest.getParentSignBook().getSignRequests().size());
List<Document> toSignDocuments = signService.getToSignDocuments(signRequest.getId());
Expand Down
Loading

0 comments on commit 623cd49

Please sign in to comment.