feat(paiements): ajout d'un système d'audit log pour les paiements avec filtres et correction d'accès agent
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 2m46s
AS Talange CI/CD Pipeline / Build & Run in Docker Container (push) Successful in 2m48s

This commit is contained in:
2026-06-22 22:44:14 +02:00
parent 08dc39f61a
commit 14c83be77a
8 changed files with 308 additions and 4 deletions
@@ -27,8 +27,8 @@ public class SecurityConfig {
.authorizeHttpRequests(auth -> auth
.requestMatchers("/css/**", "/js/**", "/images/**", "/inscription-public/**").permitAll()
.requestMatchers("/change-password").authenticated()
.requestMatchers("/utilisateurs/**", "/saisons/**", "/categories/**", "/equipes/**", "/modespaiement/**", "/equipements/**").hasRole("ADMIN")
.requestMatchers("/paiements/**", "/paiement/**").hasAnyRole("ADMIN", "TRESORERIE")
.requestMatchers("/utilisateurs/**", "/saisons/**", "/categories/**", "/equipes/**", "/modespaiement/**", "/equipements/**", "/admin/logs/**").hasRole("ADMIN")
.requestMatchers("/paiements/**", "/paiement/**").hasAnyRole("ADMIN", "TRESORERIE", "AGENT_SAISIE")
.requestMatchers("/planning/**").hasAnyRole("ADMIN", "AGENT_SAISIE")
.requestMatchers("/adherents/**", "/dotations/**").hasAnyRole("ADMIN", "TRESORERIE", "AGENT_SAISIE")
.anyRequest().authenticated()
@@ -0,0 +1,34 @@
package com.astalange.web.controller;
import com.astalange.core.repository.AuditLogPaiementRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/admin/logs/paiements")
public class AuditLogPaiementController {
private final AuditLogPaiementRepository auditLogPaiementRepository;
public AuditLogPaiementController(AuditLogPaiementRepository auditLogPaiementRepository) {
this.auditLogPaiementRepository = auditLogPaiementRepository;
}
@GetMapping
public String listLogs(
@RequestParam(required = false) String action,
@RequestParam(required = false) String utilisateur,
@RequestParam(required = false) String adherent,
Model model) {
model.addAttribute("logs", auditLogPaiementRepository.findByFilters(action, utilisateur, adherent));
model.addAttribute("paramAction", action);
model.addAttribute("paramUtilisateur", utilisateur);
model.addAttribute("paramAdherent", adherent);
return "audit/paiements_logs";
}
}
@@ -3,6 +3,8 @@ package com.astalange.web.controller;
import com.astalange.core.entity.Licence;
import com.astalange.core.entity.ModePaiement;
import com.astalange.core.entity.Paiement;
import com.astalange.core.entity.AuditLogPaiement;
import com.astalange.core.repository.AuditLogPaiementRepository;
import com.astalange.core.repository.LicenceRepository;
import com.astalange.core.repository.ModePaiementRepository;
import com.astalange.core.repository.PaiementRepository;
@@ -22,11 +24,13 @@ public class PaiementController {
private final LicenceRepository licenceRepository;
private final ModePaiementRepository modePaiementRepository;
private final PaiementRepository paiementRepository;
private final AuditLogPaiementRepository auditLogPaiementRepository;
public PaiementController(LicenceRepository licenceRepository, ModePaiementRepository modePaiementRepository, PaiementRepository paiementRepository) {
public PaiementController(LicenceRepository licenceRepository, ModePaiementRepository modePaiementRepository, PaiementRepository paiementRepository, AuditLogPaiementRepository auditLogPaiementRepository) {
this.licenceRepository = licenceRepository;
this.modePaiementRepository = modePaiementRepository;
this.paiementRepository = paiementRepository;
this.auditLogPaiementRepository = auditLogPaiementRepository;
}
@PostMapping("/licences/{id}/paiements")
@@ -58,6 +62,15 @@ public class PaiementController {
paiement.setGestionnaire(principal.getName());
}
paiementRepository.save(paiement);
AuditLogPaiement log = new AuditLogPaiement();
log.setAction("CREATE");
log.setUtilisateur(principal != null ? principal.getName() : "Système");
log.setPaiementId(paiement.getId());
log.setMontant(montant);
log.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
log.setDetails("Création d'un paiement de " + montant + "€ via " + mode.getNom() + " pour la licence " + (licence.getNumeroLicence() != null ? licence.getNumeroLicence() : "sans numéro"));
auditLogPaiementRepository.save(log);
}
return "redirect:/adherents/" + adherentId + "/edit";
@@ -78,6 +91,9 @@ public class PaiementController {
ModePaiement mode = modePaiementRepository.findById(modePaiementId)
.orElseThrow(() -> new IllegalArgumentException("Invalid ModePaiement ID"));
BigDecimal ancienMontant = paiement.getMontant();
String ancienMode = paiement.getModePaiement().getNom();
Licence licence = paiement.getLicence();
// Validation basique pour ne pas dépasser le montant total de la licence
@@ -94,6 +110,15 @@ public class PaiementController {
paiement.setGestionnaire(principal.getName());
}
paiementRepository.save(paiement);
AuditLogPaiement log = new AuditLogPaiement();
log.setAction("UPDATE");
log.setUtilisateur(principal != null ? principal.getName() : "Système");
log.setPaiementId(paiement.getId());
log.setMontant(montant);
log.setAdherentNomComplet(licence.getAdherent().getNom() + " " + licence.getAdherent().getPrenom());
log.setDetails("Modification du paiement: montant " + ancienMontant + "€ -> " + montant + "€, mode " + ancienMode + " -> " + mode.getNom());
auditLogPaiementRepository.save(log);
}
if (redirect != null && !redirect.isEmpty()) {
@@ -105,12 +130,23 @@ public class PaiementController {
@PostMapping("/paiements/{id}/delete")
public String deletePaiement(
@PathVariable Long id,
@RequestParam(required = false) String redirect) {
@RequestParam(required = false) String redirect,
Principal principal) {
Paiement paiement = paiementRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid Paiement ID"));
Long adherentId = paiement.getLicence().getAdherent().getId();
AuditLogPaiement log = new AuditLogPaiement();
log.setAction("DELETE");
log.setUtilisateur(principal != null ? principal.getName() : "Système");
log.setPaiementId(paiement.getId());
log.setMontant(paiement.getMontant());
log.setAdherentNomComplet(paiement.getLicence().getAdherent().getNom() + " " + paiement.getLicence().getAdherent().getPrenom());
log.setDetails("Suppression du paiement de " + paiement.getMontant() + "€ via " + paiement.getModePaiement().getNom());
auditLogPaiementRepository.save(log);
paiementRepository.delete(paiement);
if (redirect != null && !redirect.isEmpty()) {