Skip to content

Commit

Permalink
Merge pull request #457 from EsupPortail/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dlemaignent authored Oct 2, 2024
2 parents 27e157b + f089e4e commit b19eb86
Show file tree
Hide file tree
Showing 47 changed files with 1,020 additions and 1,011 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.30.1</version>
<version>1.30.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 @@ -65,10 +65,12 @@ and size(sb.signRequests) > 0
and (:docTitleFilter is null or sb.subject = :docTitleFilter)
and (:recipientUser is null or key(rhs).user = :recipientUser or :recipientUser in (u))
and (:creatorFilter is null or sb.createBy = :creatorFilter)
and (:statusFilter is null or sb.status = :statusFilter)
and sb.status <> 'deleted' and (sb.deleted is null or sb.deleted != true)
and size(sb.signRequests) > 0
and (sb.createDate between :startDateFilter and :endDateFilter)
""")
Page<SignBook> findByWorkflowName(User recipientUser, String workflowFilter, String docTitleFilter, User creatorFilter, Date startDateFilter, Date endDateFilter, Pageable pageable);
Page<SignBook> findByWorkflowName(User recipientUser, SignRequestStatus statusFilter, String workflowFilter, String docTitleFilter, User creatorFilter, Date startDateFilter, Date endDateFilter, Pageable pageable);

@Query("""
select distinct sb.subject from SignBook sb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private void addPropertie(User user, Field field, String value) {
fieldPropertieRepository.save(fieldPropertie);
}

@Transactional
public List<String> getFavoritesValues(String userEppn, Long id) {
List<String> favoriteValues = new ArrayList<>();
FieldPropertie fieldPropertie = getFieldPropertie(id, userEppn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public Long nbToSignSignBooks(String userEppn) {
}

@Transactional
public Page<SignBook> getSignBooksForManagers(String userEppn, String authUserEppn, String statusFilter, String recipientsFilter, String workflowFilter, String docTitleFilter, String creatorFilter, String dateFilter, Pageable pageable) {
public Page<SignBook> getSignBooksForManagers(String userEppn, String authUserEppn, SignRequestStatus statusFilter, String recipientsFilter, String workflowFilter, String docTitleFilter, String creatorFilter, String dateFilter, Pageable pageable) {
User creatorFilterUser = null;
if(creatorFilter != null) {
creatorFilterUser = userService.getByEppn(creatorFilter);
Expand All @@ -210,7 +210,7 @@ public Page<SignBook> getSignBooksForManagers(String userEppn, String authUserEp
logger.error("unable to parse date : " + dateFilter);
}
}
return signBookRepository.findByWorkflowName(userFilter, workflowFilter, docTitleFilter, creatorFilterUser, startDateFilter, endDateFilter, pageable);
return signBookRepository.findByWorkflowName(userFilter, statusFilter, workflowFilter, docTitleFilter, creatorFilterUser, startDateFilter, endDateFilter, pageable);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.esupportail.esupsignature.service.mail;

import jakarta.annotation.Resource;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import jakarta.transaction.Transactional;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.angus.mail.smtp.SMTPAddressFailedException;
import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.config.mail.MailConfig;
import org.esupportail.esupsignature.entity.*;
Expand All @@ -13,7 +18,6 @@
import org.esupportail.esupsignature.service.UserShareService;
import org.esupportail.esupsignature.service.ldap.entry.OrganizationalUnitLdap;
import org.esupportail.esupsignature.service.ldap.entry.PersonLdap;
import org.esupportail.esupsignature.entity.Otp;
import org.esupportail.esupsignature.service.utils.file.FileService;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand All @@ -30,10 +34,6 @@
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import jakarta.annotation.Resource;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import jakarta.transaction.Transactional;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Expand Down Expand Up @@ -483,7 +483,9 @@ private void sendMail(MimeMessage mimeMessage, Workflow workflow) {
mailSender.send(mimeMessage);
}
} catch (MessagingException e) {
throw new RuntimeException(e);
if(!(e instanceof SMTPAddressFailedException)) {
throw new RuntimeException(e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public boolean generateOtpForSignRequest(Long id, Long extUserId, String phone)
String urlId = UUID.randomUUID().toString();
otp.setUrlId(urlId);
signBook.setLastOtp(urlId);
removeOtpFromCache(extUser.getEppn());
removeOtpFromCache(extUser.getEmail());
removeOtpFromCache(extUser.getEppn(), signBook);
removeOtpFromCache(extUser.getEmail(), signBook);
otpCache.put(urlId, otp);
if(StringUtils.hasText(phone)) {
userService.updatePhone(extUser.getEppn(), phone);
Expand All @@ -98,9 +98,9 @@ public boolean generateOtpForSignRequest(Long id, Long extUserId, String phone)
}
}

public void removeOtpFromCache(String searchString) {
public void removeOtpFromCache(String searchString, SignBook signBook) {
for (Map.Entry<String, Otp> otpEntry : otpCache.asMap().entrySet()) {
if(otpEntry.getValue().getUser().getEmail().equals(searchString) || (otpEntry.getValue().getPhoneNumber() != null && otpEntry.getValue().getPhoneNumber().equals(searchString))) {
if(otpEntry.getValue().getSignBook().equals(signBook) && (otpEntry.getValue().getUser().getEmail().equals(searchString) || (otpEntry.getValue().getPhoneNumber() != null && otpEntry.getValue().getPhoneNumber().equals(searchString)))) {
clearOTP(otpEntry.getKey());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public String index() {
return "admin/index";
}

@GetMapping("/trigger-error")
public String triggerError() {
throw new RuntimeException("Test error 500");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

Expand Down Expand Up @@ -77,7 +78,10 @@ public String list(@ModelAttribute("userEppn") String userEppn, @ModelAttribute(
@RequestParam(value = "creatorFilter", required = false) String creatorFilter,
@RequestParam(value = "dateFilter", required = false) String dateFilter,
@SortDefault(value = "createDate", direction = Sort.Direction.DESC) @PageableDefault(size = 10) Pageable pageable, @PathVariable Long id, Model model) {
if(statusFilter == null || statusFilter.equals("all")) statusFilter = "";
SignRequestStatus signRequestStatus = null;
if(StringUtils.hasText(statusFilter) && !statusFilter.equals("all")) {
signRequestStatus = SignRequestStatus.valueOf(statusFilter);
}
if(creatorFilter == null || creatorFilter.isEmpty() || creatorFilter.equals("all")) {
creatorFilter = "%";
}
Expand All @@ -95,7 +99,7 @@ public String list(@ModelAttribute("userEppn") String userEppn, @ModelAttribute(
model.addAttribute("creatorFilter", creatorFilter);
model.addAttribute("statusFilter", statusFilter);
model.addAttribute("workflow", workflow);
Page<SignBook> signBooks = signBookService.getSignBooksForManagers(userEppn, authUserEppn, statusFilter, recipientsFilter, workflow.getDescription(), docTitleFilter, creatorFilter, dateFilter, pageable);
Page<SignBook> signBooks = signBookService.getSignBooksForManagers(userEppn, authUserEppn, signRequestStatus, recipientsFilter, workflow.getDescription(), docTitleFilter, creatorFilter, dateFilter, pageable);
model.addAttribute("signBooks", signBooks);
model.addAttribute("docTitles", signBookService.getSignBooksForManagersSubjects(workflow.getDescription()));
model.addAttribute("creators", signBookService.getSignBooksForManagersCreators(workflow.getDescription()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String list(@ModelAttribute("userEppn") String userEppn, @ModelAttribute(
@RequestParam(value = "docTitleFilter", required = false) String docTitleFilter,
@RequestParam(value = "creatorFilter", required = false) String creatorFilter,
@RequestParam(value = "dateFilter", required = false) String dateFilter,
@SortDefault(value = "createDate", direction = Sort.Direction.DESC) @PageableDefault(size = 10) Pageable pageable, Model model) {
@SortDefault(value = "createDate", direction = Sort.Direction.DESC) @PageableDefault(size = 15) Pageable pageable, Model model) {
if(statusFilter == null || statusFilter.equals("all")) statusFilter = "";
if(workflowFilter != null && (workflowFilter.isEmpty() || workflowFilter.equals("all"))) {
workflowFilter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public ResponseEntity<?> start(@PathVariable Long id,
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.ok("-1");
return ResponseEntity.internalServerError().body("-1");
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ public ResponseEntity<?> startWithDoc(@PathVariable Long id,
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.ok("-1");
return ResponseEntity.internalServerError().body("-1");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ public ResponseEntity<?> create(@Parameter(description = "Multipart stream du fi
}
} catch (EsupSignatureException e) {
logger.error(e.getMessage(), e);
return ResponseEntity.ok("-1");
return ResponseEntity.internalServerError().body("-1");
}
}
return ResponseEntity.ok("-1");
return ResponseEntity.internalServerError().body("-1");
}

@CrossOrigin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ResponseEntity<?> start(@PathVariable Long id,
}
} catch (EsupSignatureRuntimeException e) {
logger.error(e.getMessage(), e);
return ResponseEntity.ok("-1");
return ResponseEntity.internalServerError().body("-1");
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ server:
mbeanregistry:
enabled: true
remoteip:
protocol-header: X-Forwarded-Proto
remote-ip-header: X-Forwarded-For
# internal-proxies: 192\\.168\\.\\d{1,3}\\.\\d{1,3}
basedir: ./temp
max-swallow-size: -1
sign:
Expand Down
7 changes: 2 additions & 5 deletions src/main/resources/static/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ header {

.table-fix-head {
overflow-y: auto;
height: calc(100vh - 250px);
height: calc(100vh - 150px);
}

.table-fix-head thead th {
Expand Down Expand Up @@ -105,10 +105,6 @@ header {
overflow: auto;
}

.workflow-button {
z-index: 10;
}

.workspace {
margin-top: 128px;
display: flex;
Expand Down Expand Up @@ -162,6 +158,7 @@ header {

.workflow-btn {
height: 170px;
z-index: 10;
}

.workflow-btn-perso {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/static/css/overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ textarea:invalid {
max-height: 80%;
}

.card {
border: 0;
}

.card-header {
font-weight: bold;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ td {
border-radius: 4px;
border: 1px solid black;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.02) inset;
background-color: white;
}

#sidebar {
Expand Down Expand Up @@ -546,7 +547,7 @@ input:focus, textarea:focus, select:focus {
white-space: normal;
cursor: pointer;
border: 0;
border-radius: .125rem;
border-radius: .3rem;
-webkit-box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12) !important;
box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12) !important;
-webkit-transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,-webkit-box-shadow 0.15s ease-in-out !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class ListSignBooksUi {
if(urlParams.get("sort") != null) {
sort = urlParams.get("sort");
}
$.get("/" + this.mode + "/signbooks/list-ws?statusFilter=" + this.statusFilter + "&sort=" + sort + "&recipientsFilter=" + this.recipientsFilter + "&workflowFilter=" + this.workflowFilter + "&docTitleFilter=" + this.docTitleFilter + "&" + this.csrf.parameterName + "=" + this.csrf.token + "&page=" + this.page + "&size=10", function (data) {
$.get("/" + this.mode + "/signbooks/list-ws?statusFilter=" + this.statusFilter + "&sort=" + sort + "&recipientsFilter=" + this.recipientsFilter + "&workflowFilter=" + this.workflowFilter + "&docTitleFilter=" + this.docTitleFilter + "&" + this.csrf.parameterName + "=" + this.csrf.token + "&page=" + this.page + "&size=15", function (data) {
self.signRequestTable.append(data);
let clickableRows = $(".clickable-row");
clickableRows.unbind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SignPosition extends EventFactory {
self.scrollTop = $(this).scrollTop();
});
$(document).ready(function() {
if(self.signImages.length === 1) {
if(self.signImages != null && self.signImages.length === 1) {
self.popUserUi();
}
});
Expand Down
82 changes: 41 additions & 41 deletions src/main/resources/templates/admin/currentsessions.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,51 @@
</ol>
</nav>
<div id="content" class="content">
<div class="card col-lg-10 mx-auto mb-1">
<div class="card text-bg-light col-lg-11 m-2">
<div class="card-header bg-transparent border-light-subtle p-0 pt-1">
<h5 class="ms-4"><b>Sessions courantes</b></h5>
</div>
<div class="card-body">
<h5 class="text-center"><b>Utilisateurs connectés</b></h5>
<span th:text="${httpSessions.size()} + ' session(s) ouverte(s)'"></span>
</div>
</div>
<div class="card mb-1 col-10 mx-auto">
<div class="card-body">
<table class="table table-hover table-responsive">
<tr class="table-secondary">
<th>EPPN</th>
<th>Session ID</th>
<th>Creation time</th>
<th>Remote Ip</th>
<th>Url d'origine</th>
<th>Last access time</th>
<th>Inactif depuis</th>
<th>Alive</th>
<th>Delete</th>
</tr>
<tr th:each="httpSession : ${httpSessions}" th:class="${httpSession.userEppn == null && httpSession.originRequestUri != '/login/casentry'} ? 'table-danger' : ''">
<!--/*@thymesVar id="httpSession" type="org.springframework.session.MapSession"*/-->
<td th:if="${httpSession.userEppn != null}">
<input type="text" th:value="${httpSession.userEppn}" disabled>
</td>
<td th:unless="${httpSession.userEppn != null}">Anonyme</td>
<td th:text="${httpSession.sessionId}"></td>
<td th:text="${#dates.format(httpSession.createdDate, 'dd/MM/yyyy HH:mm:ss')}"></td>
<td th:text="${httpSession.remoteIp}"></td>
<td th:text="${httpSession.originRequestUri}"></td>
<td th:text="${#dates.format(httpSession.lastRequest, 'dd/MM/yyyy HH:mm:ss')}"></td>
<td><span th:if="${httpSession.lastRequest != null}" th:text="${(#dates.createNow().toInstant().toEpochMilli() - httpSession.lastRequest.toInstant().toEpochMilli()) / 1000 / 60 + ' mins'}"></span></td>
<td>
<i th:class="${httpSession.expired} ? 'text-danger fa-solid fa-times-circle' : 'text-success fa-solid fa-check-circle'"></i>
</td>
<td>
<form th:action="'/admin/currentsessions'" th:method="'delete'">
<input type="hidden" name="sessionId" th:value="${httpSession.sessionId}"/>
<button type="submit" class="btn btn-sm btn-danger"><i
class="fa-solid fa-trash-alt"></i></button>
</form>
</td>
</tr>
</table>
</div>
<div class="table-fix-head scrollbar-style rounded-3 col-sm-9 col-md-10 col-xl-11 p-0 m-2">
<table class="table table-hover table-responsive">
<tr class="table-secondary">
<th>EPPN</th>
<th>Session ID</th>
<th>Creation time</th>
<th>Remote Ip</th>
<th>Url d'origine</th>
<th>Last access time</th>
<th>Inactif depuis</th>
<th>Alive</th>
<th>Delete</th>
</tr>
<tr th:each="httpSession : ${httpSessions}" th:class="${httpSession.userEppn == null && httpSession.originRequestUri != '/login/casentry'} ? 'table-danger' : ''">
<!--/*@thymesVar id="httpSession" type="org.springframework.session.MapSession"*/-->
<td th:if="${httpSession.userEppn != null}">
<input type="text" th:value="${httpSession.userEppn}" disabled>
</td>
<td th:unless="${httpSession.userEppn != null}">Anonyme</td>
<td th:text="${httpSession.sessionId}"></td>
<td th:text="${#dates.format(httpSession.createdDate, 'dd/MM/yyyy HH:mm:ss')}"></td>
<td th:text="${httpSession.remoteIp}"></td>
<td th:text="${httpSession.originRequestUri}"></td>
<td th:text="${#dates.format(httpSession.lastRequest, 'dd/MM/yyyy HH:mm:ss')}"></td>
<td><span th:if="${httpSession.lastRequest != null}" th:text="${(#dates.createNow().toInstant().toEpochMilli() - httpSession.lastRequest.toInstant().toEpochMilli()) / 1000 / 60 + ' mins'}"></span></td>
<td>
<i th:class="${httpSession.expired} ? 'text-danger fa-solid fa-times-circle' : 'text-success fa-solid fa-check-circle'"></i>
</td>
<td>
<form th:action="'/admin/currentsessions'" th:method="'delete'">
<input type="hidden" name="sessionId" th:value="${httpSession.sessionId}"/>
<button type="submit" class="btn btn-sm btn-danger"><i
class="fa-solid fa-trash-alt"></i></button>
</form>
</td>
</tr>
</table>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit b19eb86

Please sign in to comment.