Skip to content

Commit

Permalink
Merge branch 'release/2023.11.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
juliette-derancourt committed Nov 21, 2023
2 parents fb2d150 + a50b777 commit edbdda6
Show file tree
Hide file tree
Showing 20 changed files with 320 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import fr.gouv.bo.service.LogService;
import fr.gouv.bo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.security.Principal;
Expand Down Expand Up @@ -36,4 +38,17 @@ public String myDashboard(Model model, Principal principal) {
model.addAttribute(EMAIL, new EmailDTO());
return "bo/dashboard";
}
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/{userId}")
public String boUserDashboard(Model model, @PathVariable Long userId) {
BOUser operator = userService.findUserById(userId);
List<Object[]> listTreatedCountByDay = logService.listLastTreatedFilesByOperator(operator.getId());

model.addAttribute("operator", operator);
model.addAttribute("listTreatedCountByDay", listTreatedCountByDay);

model.addAttribute(EMAIL, new EmailDTO());
return "bo/dashboard";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.security.Principal;
Expand All @@ -72,6 +73,7 @@ public class BOTenantController {
private static final String REDIRECT_BO = "redirect:/bo";
private static final String CUSTOM_MESSAGE = "customMessage";
private static final String CLARIFICATION = "clarification";
private static final String OPERATOR_COMMENT = "operatorComment";
private static final String REDIRECT_ERROR = "redirect:/error";

private final TenantService tenantService;
Expand All @@ -90,15 +92,15 @@ public class BOTenantController {
public String getTenant(@PathVariable Long id) {
Tenant tenant = tenantService.findTenantById(id);
if (tenant != null) {
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
return redirectToTenantPage(tenant);
}
throw new ObjectNotFoundException("TENANT", "Tenant is not found. Still exists?");
}

@GetMapping("/setAsTenantCreate/{id}")
public String setAsTenantCreate(@PathVariable Long id) {
Tenant tenant = userService.setAsTenantCreate(tenantService.findTenantById(id));
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
return redirectToTenantPage(tenant);
}

@GetMapping("/deleteCoTenant/{id}")
Expand Down Expand Up @@ -158,7 +160,7 @@ public String deleteDocument(@PathVariable("id") Long id, Principal principal) {
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
User operator = userService.findUserByEmail(principal.getName());
tenantService.updateTenantStatus(tenant, operator);
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
return redirectToTenantPage(tenant);
}

@GetMapping("/status/{id}")
Expand All @@ -167,7 +169,7 @@ public String changeStatusOfDocument(@PathVariable("id") Long id, MessageDTO mes
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
User operator = userService.findUserByEmail(principal.getName());
tenantService.updateTenantStatus(tenant, operator);
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
return redirectToTenantPage(tenant);
}
private void checkPartnerRights(Tenant tenant, Principal principal){
BOUser operator = userService.findUserByEmail(principal.getName());
Expand Down Expand Up @@ -195,7 +197,8 @@ public String processFileForm(Model model, @PathVariable("id") Long id, Principa
model.addAttribute(NEW_MESSAGE, findNewMessageFromTenant(id));
model.addAttribute(TENANT, tenant);
model.addAttribute(CUSTOM_MESSAGE, getCustomMessage(tenant));
model.addAttribute(CLARIFICATION, getClarificationParagraphs(tenant));
model.addAttribute(CLARIFICATION, splitInParagraphs(tenant.getClarification()));
model.addAttribute(OPERATOR_COMMENT, splitInParagraphs(tenant.getOperatorComment()));
return "bo/process-file";
}

Expand All @@ -205,7 +208,7 @@ public String deleteGuarantor(@PathVariable("guarantorId") Long guarantorId, Pri
apartmentSharingService.resetDossierPdfGenerated(tenant.getApartmentSharing());
User operator = userService.findUserByEmail(principal.getName());
tenantService.updateTenantStatus(tenant, operator);
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
return redirectToTenantPage(tenant);
}

private Boolean findNewMessageFromTenant(Long id) {
Expand All @@ -227,6 +230,18 @@ public String processFile(@PathVariable("id") Long id, CustomMessage customMessa
return tenantService.redirectToApplication(principal, null);
}

@PostMapping("/{id}/comment")
public String addOperatorComment(@PathVariable("id") Long id, @RequestParam String comment) {
Tenant tenant = tenantService.find(id);
tenant.setOperatorComment(comment);
tenantService.save(tenant);
return redirectToTenantPage(tenant);
}

private static String redirectToTenantPage(Tenant tenant) {
return "redirect:/bo/colocation/" + tenant.getApartmentSharing().getId() + "#tenant" + tenant.getId();
}

private List<ItemDetail> getItemDetailForSubcategoryOfDocument(DocumentSubCategory documentSubCategory, String tenantOrGuarantor) {

List<ItemDetail> itemDetails = new ArrayList<>();
Expand Down Expand Up @@ -298,11 +313,11 @@ private CustomMessage getCustomMessage(Tenant tenant) {
return customMessage;
}

private static List<String> getClarificationParagraphs(Tenant tenant) {
if (tenant.getClarification() == null) {
private static List<String> splitInParagraphs(String string) {
if (string == null) {
return Collections.emptyList();
}
return Arrays.stream(tenant.getClarification().split("\n"))
return Arrays.stream(string.split("\n"))
.filter(paragraph -> !paragraph.isBlank())
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public BOUser findUserByEmail(String email) {
return userRepository.findByEmail(email).orElse(null);
}

public BOUser findUserById(Long id) {
return userRepository.findById(id).orElse(null);
}

public void delete(Long id) {
userRepository.deleteById(id);
}
Expand Down
2 changes: 1 addition & 1 deletion dossierfacile-bo/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ document_sub_category.NO_ACTIVITY=Sans emploi
document_sub_category.ARTIST=Artiste-auteur
document_sub_category.OTHER=Autre
document_sub_category.SALARY=Revenus professionels
document_sub_category.SALARY=Revenus professionnels
document_sub_category.SCHOLARSHIP=Bourses
document_sub_category.SOCIAL_SERVICE=Prestations sociales
document_sub_category.RENT=Rentes
Expand Down
12 changes: 12 additions & 0 deletions dossierfacile-bo/src/main/resources/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ input.form-control {
height: 40px;
}

.input {
width: 100%;
background: #fff;
border: 1px solid #c6cbd3;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 10px;
margin-bottom: 10px;
display: block;
border-radius: 6px;
}

.navbar-brand {
padding: 5px 15px 15px 15px !important;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,33 +404,80 @@ <h5 class="modal-title bold" style="width: 80%;float: left;">
</div>
</div>
</div>


</div>
</div>
<div class="row" style="margin-bottom: 8px;">
<div class="col-md-12"
th:style="${partnerListByTenant.getNamesOfPartnerByTenantId(tenant.getId()).isEmpty()}?'display:none':'margin-bottom: 8px;'">
<div class="col-md-1">
<h4 style="margin-left: -15px;">Partner(s)</h4>
<div class="row" style="margin-top: 0.5em">
<div class="col-md-10">
<a class="btn btn-warning bo-btn" data-toggle="modal"
th:data-target="'#add-comment-'+${tenant.getId()}">
<span th:text="${T(org.apache.commons.lang3.StringUtils).isBlank(tenant.getOperatorComment())} ? 'Ajouter un commentaire' : 'Editer le commentaire'"></span>
</a>
</div>
<div class=" col-md-11">
<div class="scrollmenu"
style="background-color: #333;overflow: auto;white-space: nowrap;margin-right: -12px">
<a href="#"
style="display: inline-block;color: white;text-align: center;padding: 14px;text-decoration: none;"
th:each="item : ${partnerListByTenant.getNamesOfPartnerByTenantId(tenant.getId())}"
th:text="${item}"></a>
<div class="modal fade" th:id="'add-comment-' + ${tenant.getId()}" role="dialog"
tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title bold" style="width: 80%;float: left;">
Précisions concernant le traitement du dossier
</h5>
<button aria-label="Close" class="close" data-dismiss="modal"
type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>

<form method="post" th:action="@{/bo/tenant/__${tenant.getId()}__/comment}">
<div class="modal-body">
<textarea id="comment" name="comment" class="input" rows="6"
type="text" th:text="${tenant.getOperatorComment()}"></textarea>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info btn-save"
style="border-radius: 50px;font-size: 15px;line-height: 1;padding: 5px 8px 7px;">
Sauvegarder
</button>
<button class="btn btn-secondary" data-dismiss="modal"
style="border-radius: 50px;font-size: 15px;line-height: 1;padding: 5px 8px 7px;"
type="button">
Annuler
</button>
</div>
</form>

</div>
</div>
</div>
</div>
</div>

<div class="table-responsive">

<table class="table table-striped table-bordered table-hover"
th:with="partners=${partnerListByTenant.getNamesOfPartnerByTenantId(tenant.getId())}">
<tr th:if="${tenant.getOperatorComment() != null && !tenant.getOperatorComment().isEmpty()}">
<td style="width: 25%">⚠️ Commentaire opérateur</td>
<td th:text="${tenant.getOperatorComment()}"></td>
</tr>
<tr th:if="${!partners.isEmpty()}">
<td>Partenaire(s)</td>
<td>
<ul>
<li
th:each="item : ${partners}"
th:text="${item}"
>
</li>
</ul>
</td>
</tr>
</table>
</div>

<div class="table-responsive">

<table class="table table-striped table-bordered table-hover">
<tr>
<td>Tenant Id</td>
<td style="width: 25%">Tenant Id</td>
<td th:text="${tenant.getId()}"></td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
margin-bottom: 1em;
}

.input {
width: 100%;
background: #fff;
border: 1px solid #c6cbd3;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 10px;
margin-bottom: 10px;
display: block;
border-radius: 6px;
}

.btn-save {
font-size: initial;
float: right;
Expand Down Expand Up @@ -79,6 +67,17 @@
<label for="messageValue">Message</label>
<textarea id="messageValue" class="input" rows="4" required
th:field="*{messageValue}"></textarea>
<div style="font-size: 12px">
<p>
<strong>Note :</strong>
Le format <a style="text-decoration: underline" href="https://www.markdownguide.org/basic-syntax">markdown</a> est supporté dans le message.
</p>
<ul>
<li>Pour faire un lien : <code>[texte du lien](url)</code></li>
<li>Pour mettre en italique : <code>*texte*</code></li>
<li>Pour mettre en gras : <code>**texte**</code></li>
</ul>
</div>
</div>
<button type="submit" class="btn btn-info btn-save">Sauvegarder</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
margin-bottom: 1em;
}

.input {
width: 100%;
background: #fff;
border: 1px solid #c6cbd3;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 10px;
margin-bottom: 10px;
display: block;
border-radius: 6px;
}

.disabled {
background: lightgrey;
}
Expand Down
14 changes: 12 additions & 2 deletions dossierfacile-bo/src/main/resources/templates/bo/process-file.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@

<div>
<div th:if="${!clarification.isEmpty()}"
class="panel-heading file1-background-color letter col-md-8"
style="margin: 0 0 20px 10px; padding-top: 15px; line-height: 20px"
class="file1-background-color letter col-md-8"
style="margin: 0 0 10px 10px; padding-top: 15px; line-height: 20px"
>
<p style="font-size: 12px">Mot du locataire :</p>
<p th:each="paragraph : ${clarification}" th:text="${paragraph}"></p>
</div>
</div>

<div>
<div th:if="${!operatorComment.isEmpty()}"
class="file1-background-color letter col-md-8"
style="margin: 0 0 10px 10px; padding-top: 15px; line-height: 20px;"
>
<p style="font-size: 12px">⚠️ Commentaire opérateur :</p>
<p th:each="paragraph : ${operatorComment}" th:text="${paragraph}"></p>
</div>
</div>

<div th:each="messageItem, i:${customMessage.getMessageItems()}" th:remove="tag">
<div class="col-md-8 back-color" style="height: 700px" th:if="${messageItem.getCustomTex()}==null">
<embed class="document-embed" height="90%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class Tenant extends User implements Person, Serializable {

private int warnings;

private String operatorComment;

private transient String warningMessage;

public static TenantBuilder<?, ?> builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,6 @@ SELECT COUNT(t.id)
)
List<Tenant> findAllTenantsValidatedSinceXDaysAgo(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);

@Query(value = "from Tenant t " +
"where t.lastLoginDate < :localDateTime " +
"and t.warnings = :warnings " +
"and t.id in (select d.tenant.id from Document d where d.tenant.id is not null)")
Page<Tenant> findByLastLoginDateIsBeforeAndHasDocuments(Pageable pageable, @Param("localDateTime") LocalDateTime localDateTime, @Param("warnings") Integer warnings);

@Query(value = "select count(*) from Tenant t " +
"where t.lastLoginDate < :localDateTime " +
"and t.warnings = :warnings " +
"and t.id in (select d.tenant.id from Document d where d.tenant.id is not null)")
long countByLastLoginDateIsBeforeAndHasDocuments(@Param("localDateTime") LocalDateTime localDateTime, @Param("warnings") Integer warnings);

@Modifying
@Query("UPDATE Tenant t SET t.warnings = 0 where t.id = :tenantId")
void resetWarnings(@Param("tenantId") Long tenantId);
Expand Down Expand Up @@ -281,9 +269,6 @@ OR creation_date > CAST(CAST(:lastUpdateFrom AS text) AS timestamp))
)
List<TenantUpdate> findTenantUpdateByCreationDateAndPartner(@Param("creationDateFrom") LocalDateTime from, @Param("partnerId") Long id, @Param("limit") Long limit);

@Query("SELECT t.id FROM Tenant t WHERE t.status = :status AND t.lastUpdateDate < :before")
List<Long> findByStatusAndLastUpdateDate(@Param("status") TenantFileStatus status, @Param("before") LocalDateTime before, Pageable pageable);

@Query("""
SELECT DISTINCT t
FROM Tenant t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@
<include file="db/migration/202310300000-update-property-log-table.xml" />
<include file="db/migration/202311080001-add-processed-documents-time-spent-column.xml" />
<include file="db/migration/202311090000-update-user-account-table.xml" />
<include file="db/migration/202311170000-update-tenant-table.xml" />

</databaseChangeLog>
Loading

0 comments on commit edbdda6

Please sign in to comment.