6 Commits
Author SHA1 Message Date
ucef 1737087062 feat: track user login and logout timestamps in session management
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 4m15s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 5m55s
2026-07-31 10:26:14 +02:00
ucef df217bc923 fix: update equipment size matching pattern recognition and add integration tests
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 4m14s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 6m9s
- Prevent false positive regex matches by enforcing strict digit boundaries in Dotation.isSizeMatch
- Fix issue where 11/12ANS (Taille 152cm) mapped to 5/6ANS (Taille 116cm) due to 'Taille 1' tag matching '116cm'
- Add comprehensive integration test (DotationIntegrationTest) covering all Junior/Adult sizes, shoe sizes, and format variations
2026-07-30 10:12:21 +02:00
ucef da0443f655 fix: improve adherent size matching and conditional visibility in dotations
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 4m12s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 6m0s
2026-07-29 16:28:51 +02:00
ucef baa4d3c0cd feat: map adherent size and shoe size to dotations
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 4m35s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 6m1s
2026-07-17 23:55:44 +02:00
ucef e81be98cbe fix: correct hx-vals JSON syntax for payments pagination
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 4m42s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 6m50s
2026-07-17 23:41:20 +02:00
ucef a19e49392b chore: bump version to 1.6-SNAPSHOT
AS Talange CI/CD Pipeline / Build & Run Unit Tests (push) Successful in 3m57s
AS Talange CI/CD Pipeline / Deploy to Test Environment (push) Successful in 5m50s
2026-07-08 02:50:26 +02:00
16 changed files with 633 additions and 36 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>as-talange-parent</artifactId>
<groupId>com.astalange</groupId>
<version>1.5</version>
<version>1.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>as-talange-parent</artifactId>
<groupId>com.astalange</groupId>
<version>1.5</version>
<version>1.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -36,4 +36,10 @@ public class AppUser {
inverseJoinColumns = @JoinColumn(name = "role_id")
)
private Set<Role> roles = new HashSet<>();
@Column(name = "last_login_at")
private java.time.LocalDateTime lastLoginAt;
@Column(name = "last_logout_at")
private java.time.LocalDateTime lastLogoutAt;
}
@@ -64,4 +64,107 @@ public class Dotation {
public Boolean getChoisi() { return choisi; }
public void setChoisi(Boolean choisi) { this.choisi = choisi; }
public static boolean isSizeMatch(String option, String adherentSize) {
if (option == null || adherentSize == null) return false;
String opt = option.trim();
String adh = adherentSize.trim();
if (opt.isEmpty() || adh.isEmpty()) return false;
if (opt.equalsIgnoreCase(adh)) return true;
String optNorm = opt.toLowerCase().replaceAll("\\s+", " ");
String adhNorm = adh.toLowerCase().replaceAll("\\s+", " ");
if (optNorm.equals(adhNorm)) return true;
// 1. Age bracket matching: 5/6, 7/8, 9/10, 11/12, 13/14, 15/16
java.util.regex.Pattern agePattern = java.util.regex.Pattern.compile("(?<!\\d)(5[/\\-]6|7[/\\-]8|9[/\\-]10|11[/\\-]12|13[/\\-]14|15[/\\-]16)(?!\\d)");
java.util.regex.Matcher adhAgeMatcher = agePattern.matcher(adhNorm);
java.util.regex.Matcher optAgeMatcher = agePattern.matcher(optNorm);
boolean adhHasAge = adhAgeMatcher.find();
boolean optHasAge = optAgeMatcher.find();
if (adhHasAge && optHasAge) {
String adhAgeKey = adhAgeMatcher.group(1).replace("-", "/");
String optAgeKey = optAgeMatcher.group(1).replace("-", "/");
return adhAgeKey.equals(optAgeKey);
} else if (adhHasAge) {
String ageKey = adhAgeMatcher.group(1).replace("-", "/");
String altAgeKey = ageKey.replace("/", "-");
if (optNorm.contains(ageKey) || optNorm.contains(altAgeKey)) {
return true;
}
}
// 2. Height matching (3-digit numbers in cm, e.g. 115, 116, 126, 128, 138, 140, 150, 152, 162, 164, 176)
java.util.regex.Pattern heightPattern = java.util.regex.Pattern.compile("(?<!\\d)(115|116|126|128|138|140|150|152|162|164|176)(?!\\d)");
java.util.regex.Matcher adhHeightMatcher = heightPattern.matcher(adhNorm);
java.util.regex.Matcher optHeightMatcher = heightPattern.matcher(optNorm);
boolean adhHasHeight = adhHeightMatcher.find();
boolean optHasHeight = optHeightMatcher.find();
if (adhHasHeight && optHasHeight) {
int adhH = Integer.parseInt(adhHeightMatcher.group(1));
int optH = Integer.parseInt(optHeightMatcher.group(1));
return Math.abs(adhH - optH) <= 5;
}
// 3. Shoe size / pointure matching: 27/30, 31/34, 35/38, 39/42, 43/46
java.util.regex.Pattern shoePattern = java.util.regex.Pattern.compile("(?<!\\d)(27[/\\-]30|31[/\\-]34|35[/\\-]38|39[/\\-]42|43[/\\-]46)(?!\\d)");
java.util.regex.Matcher adhShoeMatcher = shoePattern.matcher(adhNorm);
java.util.regex.Matcher optShoeMatcher = shoePattern.matcher(optNorm);
boolean adhHasShoe = adhShoeMatcher.find();
boolean optHasShoe = optShoeMatcher.find();
if (adhHasShoe && optHasShoe) {
String adhShoeKey = adhShoeMatcher.group(1).replace("-", "/");
String optShoeKey = optShoeMatcher.group(1).replace("-", "/");
return adhShoeKey.equals(optShoeKey);
}
// 4. Sock size tag matching: "taille 0", "taille 1", "taille 2", "taille 3", "taille 4"
java.util.regex.Pattern tNumPattern = java.util.regex.Pattern.compile("(?<![a-z0-9])taille\\s*([0-4])(?![0-9])");
java.util.regex.Matcher adhTNumMatcher = tNumPattern.matcher(adhNorm);
java.util.regex.Matcher optTNumMatcher = tNumPattern.matcher(optNorm);
boolean adhHasTNum = adhTNumMatcher.find();
boolean optHasTNum = optTNumMatcher.find();
if (adhHasTNum && optHasTNum) {
return adhTNumMatcher.group(1).equals(optTNumMatcher.group(1));
}
// 5. Letter size matching: XXL, XL, L, M, S, XS
java.util.regex.Pattern letterPattern = java.util.regex.Pattern.compile("(?<![a-z0-9])(xxl|xl|l|m|s|xs)(?![a-z0-9])");
java.util.regex.Matcher adhLetterMatcher = letterPattern.matcher(adhNorm);
java.util.regex.Matcher optLetterMatcher = letterPattern.matcher(optNorm);
boolean adhHasLetter = adhLetterMatcher.find();
boolean optHasLetter = optLetterMatcher.find();
if (adhHasLetter && optHasLetter) {
return adhLetterMatcher.group(1).equals(optLetterMatcher.group(1));
}
// Substring fallback only if neither age, height, shoe, tag, nor letter pattern were present
if (!adhHasAge && !optHasAge && !adhHasHeight && !optHasHeight && !adhHasShoe && !optHasShoe && !adhHasTNum && !optHasTNum && !adhHasLetter && !optHasLetter) {
if (optNorm.length() >= 2 && adhNorm.contains(optNorm)) return true;
if (adhNorm.length() >= 2 && optNorm.contains(adhNorm)) return true;
}
return false;
}
public boolean isTailleOptionSelected(String option) {
if (option == null) return false;
String trimmedOpt = option.trim();
if (this.taille != null && !this.taille.trim().isEmpty()) {
return this.taille.trim().equalsIgnoreCase(trimmedOpt);
}
if (this.licence == null || this.licence.getAdherent() == null) {
return false;
}
Adherent adherent = this.licence.getAdherent();
return isSizeMatch(trimmedOpt, adherent.getTailleVetement()) || isSizeMatch(trimmedOpt, adherent.getPointure());
}
}
@@ -0,0 +1,79 @@
package com.astalange.core.security;
import com.astalange.core.entity.AppUser;
import com.astalange.core.repository.AppUserRepository;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.authentication.event.LogoutSuccessEvent;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.session.HttpSessionDestroyedEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@Component
public class AuthenticationEventListener {
private final AppUserRepository userRepository;
public AuthenticationEventListener(AppUserRepository userRepository) {
this.userRepository = userRepository;
}
@EventListener
@Transactional
public void onAuthenticationSuccess(AuthenticationSuccessEvent event) {
String username = extractUsername(event.getAuthentication().getPrincipal());
if (username != null) {
userRepository.findByUsername(username).ifPresent(user -> {
user.setLastLoginAt(LocalDateTime.now());
userRepository.save(user);
});
}
}
@EventListener
@Transactional
public void onLogoutSuccess(LogoutSuccessEvent event) {
if (event.getAuthentication() != null) {
String username = extractUsername(event.getAuthentication().getPrincipal());
if (username != null) {
userRepository.findByUsername(username).ifPresent(user -> {
user.setLastLogoutAt(LocalDateTime.now());
userRepository.save(user);
});
}
}
}
@EventListener
@Transactional
public void onSessionDestroyed(HttpSessionDestroyedEvent event) {
List<SecurityContext> contexts = event.getSecurityContexts();
for (SecurityContext context : contexts) {
if (context != null && context.getAuthentication() != null) {
String username = extractUsername(context.getAuthentication().getPrincipal());
if (username != null) {
userRepository.findByUsername(username).ifPresent(user -> {
if (user.getLastLogoutAt() == null || (user.getLastLoginAt() != null && user.getLastLogoutAt().isBefore(user.getLastLoginAt()))) {
user.setLastLogoutAt(LocalDateTime.now());
userRepository.save(user);
}
});
}
}
}
}
private String extractUsername(Object principal) {
if (principal instanceof UserDetails) {
return ((UserDetails) principal).getUsername();
} else if (principal instanceof String) {
return (String) principal;
}
return null;
}
}
@@ -123,6 +123,23 @@ public class CategorieService {
continue;
}
String matchedTaille = "";
if (licence.getAdherent() != null) {
String taillesDispo = ce.getEquipement().getTaillesDisponibles();
if (taillesDispo != null && !taillesDispo.trim().isEmpty()) {
String[] dispos = taillesDispo.split(",");
String tv = licence.getAdherent().getTailleVetement();
String pt = licence.getAdherent().getPointure();
for (String t : dispos) {
String trimmed = t.trim();
if (Dotation.isSizeMatch(trimmed, tv) || Dotation.isSizeMatch(trimmed, pt)) {
matchedTaille = trimmed;
break;
}
}
}
}
boolean found = false;
for (Dotation d : currentDotations) {
if (ce.getEquipement().getId().equals(d.getEquipement().getId())) {
@@ -130,6 +147,9 @@ public class CategorieService {
if (Boolean.TRUE.equals(ce.getObligatoire()) && !Boolean.TRUE.equals(d.getChoisi())) {
d.setChoisi(true);
}
if ((d.getTaille() == null || d.getTaille().trim().isEmpty()) && !matchedTaille.isEmpty()) {
d.setTaille(matchedTaille);
}
break;
}
}
@@ -146,7 +166,7 @@ public class CategorieService {
}
newDotation.setChoisi(ce.getObligatoire() || (isMaillot && isNouvelle)); // Checked if obligatoire or if it's a new registration
newDotation.setFourni(false);
newDotation.setTaille("");
newDotation.setTaille(matchedTaille);
newDotation.setNumero("");
if (licence.getAdherent() != null) {
String defaultFlocage = "";
@@ -0,0 +1,2 @@
ALTER TABLE app_user ADD COLUMN last_login_at TIMESTAMP;
ALTER TABLE app_user ADD COLUMN last_logout_at TIMESTAMP;
@@ -0,0 +1,56 @@
package com.astalange.core;
import com.astalange.core.entity.Dotation;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DotationSizeMatchTest {
@Test
public void testAdherent60SizeMatchBugFix() {
String adherentTaille = "11/12ANS (Taille 152cm)";
String adherentPointure = "35/38 (Taille 2)";
// Equipment options for Junior Maillot / Shorts / Tracksuits
String opt56 = "5/6ANS (Taille 116cm)";
String opt78 = "7/8ANS (Taille 128cm)";
String opt910 = "9/10ANS (Taille 140cm)";
String opt1112 = "11/12ANS (Taille 152cm)";
String opt1314 = "13/14ANS (Taille 164cm)";
assertFalse(Dotation.isSizeMatch(opt56, adherentTaille), "5/6ANS should NOT match 11/12ANS");
assertFalse(Dotation.isSizeMatch(opt78, adherentTaille), "7/8ANS should NOT match 11/12ANS");
assertFalse(Dotation.isSizeMatch(opt910, adherentTaille), "9/10ANS should NOT match 11/12ANS");
assertTrue(Dotation.isSizeMatch(opt1112, adherentTaille), "11/12ANS MUST match 11/12ANS");
assertFalse(Dotation.isSizeMatch(opt1314, adherentTaille), "13/14ANS should NOT match 11/12ANS");
// Sock sizes
String sock2730 = "27/30 (Taille 0)";
String sock3134 = "31/34 (Taille 1)";
String sock3538 = "35/38 (Taille 2)";
String sock3942 = "39/42 (Taille 3)";
assertFalse(Dotation.isSizeMatch(sock2730, adherentPointure), "27/30 should NOT match 35/38");
assertFalse(Dotation.isSizeMatch(sock3134, adherentPointure), "31/34 should NOT match 35/38");
assertTrue(Dotation.isSizeMatch(sock3538, adherentPointure), "35/38 MUST match 35/38");
assertFalse(Dotation.isSizeMatch(sock3942, adherentPointure), "39/42 should NOT match 35/38");
// Ensure sock sizes do not match clothing size 152cm due to "Taille 1"
assertFalse(Dotation.isSizeMatch(sock3134, adherentTaille), "Sock 31/34 (Taille 1) should NOT match clothing 152cm");
}
@Test
public void testLetterSizes() {
assertFalse(Dotation.isSizeMatch("S", "XL"));
assertFalse(Dotation.isSizeMatch("M", "XL"));
assertTrue(Dotation.isSizeMatch("XL", "XL"));
assertTrue(Dotation.isSizeMatch("xxl", "XXL"));
}
@Test
public void testSpaceVariations() {
assertTrue(Dotation.isSizeMatch("5/6 ANS (Taille 116cm)", "5/6ANS"));
assertTrue(Dotation.isSizeMatch("11/12 ANS (Taille 152cm)", "11/12ANS (Taille 152 cm)"));
}
}
@@ -0,0 +1,214 @@
package com.astalange.core.service;
import com.astalange.core.entity.*;
import com.astalange.core.repository.CategorieRepository;
import com.astalange.core.repository.DotationRepository;
import com.astalange.core.repository.EquipementRepository;
import com.astalange.core.repository.SaisonRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(MockitoExtension.class)
public class DotationIntegrationTest {
@Mock
private CategorieRepository categorieRepository;
@Mock
private SaisonRepository saisonRepository;
@Mock
private EquipementRepository equipementRepository;
@Mock
private com.astalange.core.repository.LicenceRepository licenceRepository;
@InjectMocks
private CategorieService categorieService;
private Equipement maillotJunior;
private Equipement chaussettesJunior;
private Equipement maillotAdulte;
private Equipement chaussettesAdulte;
private Categorie catJunior;
private Categorie catAdulte;
@BeforeEach
public void setUp() {
// 1. Junior Equipment
maillotJunior = new Equipement();
maillotJunior.setId(1L);
maillotJunior.setNom("Maillot de match Puma (Junior)");
maillotJunior.setTypePublic("TOUS");
maillotJunior.setTaillesDisponibles("5/6ANS (Taille 116cm),7/8ANS (Taille 128cm),9/10ANS (Taille 140cm),11/12ANS (Taille 152cm),13/14ANS (Taille 164cm),15/16ANS (Taille 176cm)");
chaussettesJunior = new Equipement();
chaussettesJunior.setId(2L);
chaussettesJunior.setNom("Chaussettes puma (Junior)");
chaussettesJunior.setTypePublic("TOUS");
chaussettesJunior.setTaillesDisponibles("27/30 (Taille 0),31/34 (Taille 1),35/38 (Taille 2),39/42 (Taille 3)");
catJunior = new Categorie();
catJunior.setId(10L);
catJunior.setNom("U11");
CategorieEquipement ce1 = new CategorieEquipement();
ce1.setCategorie(catJunior);
ce1.setEquipement(maillotJunior);
ce1.setObligatoire(true);
CategorieEquipement ce2 = new CategorieEquipement();
ce2.setCategorie(catJunior);
ce2.setEquipement(chaussettesJunior);
ce2.setObligatoire(true);
catJunior.setCategorieEquipements(List.of(ce1, ce2));
// 2. Adult Equipment
maillotAdulte = new Equipement();
maillotAdulte.setId(3L);
maillotAdulte.setNom("Maillot de match Puma (Adulte)");
maillotAdulte.setTypePublic("TOUS");
maillotAdulte.setTaillesDisponibles("XS,S,M,L,XL,XXL");
chaussettesAdulte = new Equipement();
chaussettesAdulte.setId(4L);
chaussettesAdulte.setNom("Chaussettes puma (Adulte)");
chaussettesAdulte.setTypePublic("TOUS");
chaussettesAdulte.setTaillesDisponibles("35/38 (Taille 2),39/42 (Taille 3),43/46 (Taille 4)");
catAdulte = new Categorie();
catAdulte.setId(20L);
catAdulte.setNom("Seniors");
CategorieEquipement ce3 = new CategorieEquipement();
ce3.setCategorie(catAdulte);
ce3.setEquipement(maillotAdulte);
ce3.setObligatoire(true);
CategorieEquipement ce4 = new CategorieEquipement();
ce4.setCategorie(catAdulte);
ce4.setEquipement(chaussettesAdulte);
ce4.setObligatoire(true);
catAdulte.setCategorieEquipements(List.of(ce3, ce4));
}
private Licence createLicence(Categorie cat, String tailleVetement, String pointure) {
Adherent adherent = new Adherent();
adherent.setTypeMaillot("JOUEUR");
adherent.setTailleVetement(tailleVetement);
adherent.setPointure(pointure);
Licence licence = new Licence();
licence.setId(100L);
licence.setAdherent(adherent);
licence.setCategorie(cat);
licence.setDotations(new ArrayList<>());
return licence;
}
@Test
@DisplayName("Junior 11/12ANS (Bug initial Adhérent 60) -> Doit reporter 11/12ANS et 35/38")
public void testAdherent60Synchronization() {
Licence licence = createLicence(catJunior, "11/12ANS (Taille 152cm)", "35/38 (Taille 2)");
categorieService.syncDotationsForLicence(licence);
List<Dotation> dotations = licence.getDotations();
assertEquals(2, dotations.size());
Dotation dMaillot = dotations.stream().filter(d -> d.getEquipement().getId().equals(1L)).findFirst().orElseThrow();
Dotation dChaussettes = dotations.stream().filter(d -> d.getEquipement().getId().equals(2L)).findFirst().orElseThrow();
assertEquals("11/12ANS (Taille 152cm)", dMaillot.getTaille(), "Le maillot doit être 11/12ANS et non 5/6ANS");
assertEquals("35/38 (Taille 2)", dChaussettes.getTaille(), "Les chaussettes doivent être 35/38 et non 31/34");
}
@Test
@DisplayName("Junior - Test de toutes les tailles (5/6, 7/8, 9/10, 11/12, 13/14, 15/16)")
public void testAllJuniorSizes() {
String[][] cases = {
{"5/6ANS (Taille 116cm)", "27/30 (Taille 0)", "5/6ANS (Taille 116cm)", "27/30 (Taille 0)"},
{"7/8ANS (Taille 128cm)", "31/34 (Taille 1)", "7/8ANS (Taille 128cm)", "31/34 (Taille 1)"},
{"9/10ANS (Taille 140cm)", "31/34 (Taille 1)", "9/10ANS (Taille 140cm)", "31/34 (Taille 1)"},
{"11/12ANS (Taille 152cm)", "35/38 (Taille 2)", "11/12ANS (Taille 152cm)", "35/38 (Taille 2)"},
{"13/14ANS (Taille 164cm)", "35/38 (Taille 2)", "13/14ANS (Taille 164cm)", "35/38 (Taille 2)"},
{"15/16ANS (Taille 176cm)", "39/42 (Taille 3)", "15/16ANS (Taille 176cm)", "39/42 (Taille 3)"}
};
for (String[] testCase : cases) {
String tv = testCase[0];
String pt = testCase[1];
String expectedMaillot = testCase[2];
String expectedChaussettes = testCase[3];
Licence licence = createLicence(catJunior, tv, pt);
categorieService.syncDotationsForLicence(licence);
List<Dotation> dotations = licence.getDotations();
Dotation dMaillot = dotations.stream().filter(d -> d.getEquipement().getId().equals(1L)).findFirst().orElseThrow();
Dotation dChaussettes = dotations.stream().filter(d -> d.getEquipement().getId().equals(2L)).findFirst().orElseThrow();
assertEquals(expectedMaillot, dMaillot.getTaille(), "Erreur pour la taille vêtement: " + tv);
assertEquals(expectedChaussettes, dChaussettes.getTaille(), "Erreur pour la pointure: " + pt);
}
}
@Test
@DisplayName("Adulte - Test de toutes les tailles (XS, S, M, L, XL, XXL)")
public void testAllAdultSizes() {
String[][] cases = {
{"XS", "35/38 (Taille 2)", "XS", "35/38 (Taille 2)"},
{"S", "39/42 (Taille 3)", "S", "39/42 (Taille 3)"},
{"M", "39/42 (Taille 3)", "M", "39/42 (Taille 3)"},
{"L", "43/46 (Taille 4)", "L", "43/46 (Taille 4)"},
{"XL", "43/46 (Taille 4)", "XL", "43/46 (Taille 4)"},
{"XXL", "43/46 (Taille 4)", "XXL", "43/46 (Taille 4)"}
};
for (String[] testCase : cases) {
String tv = testCase[0];
String pt = testCase[1];
String expectedMaillot = testCase[2];
String expectedChaussettes = testCase[3];
Licence licence = createLicence(catAdulte, tv, pt);
categorieService.syncDotationsForLicence(licence);
List<Dotation> dotations = licence.getDotations();
Dotation dMaillot = dotations.stream().filter(d -> d.getEquipement().getId().equals(3L)).findFirst().orElseThrow();
Dotation dChaussettes = dotations.stream().filter(d -> d.getEquipement().getId().equals(4L)).findFirst().orElseThrow();
assertEquals(expectedMaillot, dMaillot.getTaille(), "Erreur pour la taille adulte vêtement: " + tv);
assertEquals(expectedChaussettes, dChaussettes.getTaille(), "Erreur pour la pointure adulte: " + pt);
}
}
@Test
@DisplayName("Formats alternatifs (Espaces, sans mention de taille)")
public void testAlternativeFormats() {
Licence licence1 = createLicence(catJunior, "11/12 ANS (Taille 152 cm)", "35/38 (Taille 2)");
categorieService.syncDotationsForLicence(licence1);
Dotation dMaillot1 = licence1.getDotations().stream().filter(d -> d.getEquipement().getId().equals(1L)).findFirst().orElseThrow();
assertEquals("11/12ANS (Taille 152cm)", dMaillot1.getTaille());
Licence licence2 = createLicence(catJunior, "11/12ANS", "35/38");
categorieService.syncDotationsForLicence(licence2);
Dotation dMaillot2 = licence2.getDotations().stream().filter(d -> d.getEquipement().getId().equals(1L)).findFirst().orElseThrow();
Dotation dChaussettes2 = licence2.getDotations().stream().filter(d -> d.getEquipement().getId().equals(2L)).findFirst().orElseThrow();
assertEquals("11/12ANS (Taille 152cm)", dMaillot2.getTaille());
assertEquals("35/38 (Taille 2)", dChaussettes2.getTaille());
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>as-talange-parent</artifactId>
<groupId>com.astalange</groupId>
<version>1.5</version>
<version>1.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -234,12 +234,20 @@ public class AdherentController {
existing.setLieuNaissancePays(adherent.getLieuNaissancePays());
existing.setNationalite(adherent.getNationalite());
existing.setEmail(adherent.getEmail());
existing.setTelephone(adherent.getTelephone());
existing.setRepresentantLegal(adherent.getRepresentantLegal());
existing.setResidentTalange(adherent.isResidentTalange());
existing.setSexe(adherent.getSexe());
existing.setTypeMaillot(adherent.getTypeMaillot());
existing.setTailleVetement(adherent.getTailleVetement());
existing.setPointure(adherent.getPointure());
adherentRepository.save(existing);
List<Licence> licences = licenceRepository.findByAdherentId(existing.getId());
for (Licence licence : licences) {
categorieService.syncDotationsForLicence(licence);
}
} else {
adherentRepository.save(adherent);
}
@@ -1,5 +1,8 @@
package com.astalange.web.controller;
import com.astalange.core.entity.AppUser;
import com.astalange.core.entity.Role;
import com.astalange.core.repository.AppUserRepository;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.userdetails.UserDetails;
@@ -8,7 +11,9 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Controller
@@ -16,22 +21,73 @@ import java.util.stream.Collectors;
public class SessionController {
private final SessionRegistry sessionRegistry;
private final AppUserRepository userRepository;
public SessionController(SessionRegistry sessionRegistry) {
public SessionController(SessionRegistry sessionRegistry, AppUserRepository userRepository) {
this.sessionRegistry = sessionRegistry;
this.userRepository = userRepository;
}
public static class UserSessionDTO {
private final Long id;
private final String username;
private final boolean online;
private final LocalDateTime lastLoginAt;
private final LocalDateTime lastLogoutAt;
private final String roles;
public UserSessionDTO(Long id, String username, boolean online, LocalDateTime lastLoginAt, LocalDateTime lastLogoutAt, String roles) {
this.id = id;
this.username = username;
this.online = online;
this.lastLoginAt = lastLoginAt;
this.lastLogoutAt = lastLogoutAt;
this.roles = roles;
}
public Long getId() { return id; }
public String getUsername() { return username; }
public boolean isOnline() { return online; }
public LocalDateTime getLastLoginAt() { return lastLoginAt; }
public LocalDateTime getLastLogoutAt() { return lastLogoutAt; }
public String getRoles() { return roles; }
}
@GetMapping
@PreAuthorize("hasRole('ADMIN')")
public String viewSessions(Model model) {
List<Object> principals = sessionRegistry.getAllPrincipals();
List<String> activeUsers = principals.stream()
Set<String> activeUsernames = principals.stream()
.filter(principal -> principal instanceof UserDetails)
.map(principal -> ((UserDetails) principal).getUsername())
.collect(Collectors.toList());
model.addAttribute("activeUsers", activeUsers);
model.addAttribute("activeCount", activeUsers.size());
.collect(Collectors.toSet());
List<AppUser> allUsers = userRepository.findAll();
List<UserSessionDTO> userSessions = allUsers.stream().map(user -> {
boolean isOnline = activeUsernames.contains(user.getUsername());
String rolesStr = user.getRoles().stream()
.map(Role::getName)
.map(r -> r.replace("ROLE_", ""))
.collect(Collectors.joining(", "));
return new UserSessionDTO(
user.getId(),
user.getUsername(),
isOnline,
user.getLastLoginAt(),
user.getLastLogoutAt(),
rolesStr
);
}).collect(Collectors.toList());
long activeCount = userSessions.stream().filter(UserSessionDTO::isOnline).count();
long offlineCount = userSessions.size() - activeCount;
model.addAttribute("userSessions", userSessions);
model.addAttribute("activeCount", activeCount);
model.addAttribute("offlineCount", offlineCount);
model.addAttribute("totalCount", userSessions.size());
return "admin/sessions";
}
}
@@ -413,22 +413,17 @@
<div th:if="${dot.equipement.taillesDisponibles != null and !dot.equipement.taillesDisponibles.trim().isEmpty()}">
<label class="block text-[9px] uppercase font-bold text-gray-400">Taille</label>
<select th:name="'taille_' + ${dot.id}" class="w-full text-xs border border-gray-300 rounded px-1 py-0.5 focus:ring-1 focus:ring-blue-500 outline-none">
<option value="" th:selected="${dot.taille == null or dot.taille.isEmpty()}">Choisir...</option>
<option th:if="${dot.taille != null and !dot.taille.isEmpty()}"
<option value="">Choisir...</option>
<option th:if="${dot.taille != null and !dot.taille.isEmpty() and !#strings.contains(dot.equipement.taillesDisponibles, dot.taille)}"
th:value="${dot.taille}"
th:text="${dot.taille} + ' (Actuelle)'"
selected></option>
<option th:each="t : ${#strings.arraySplit(dot.equipement.taillesDisponibles, ',')}"
th:if="${dot.taille == null or dot.taille != #strings.trim(t)}"
th:value="${#strings.trim(t)}"
th:text="${#strings.trim(t)}"
th:selected="${dot.taille == null and (#strings.trim(t) == adherent.tailleVetement or #strings.trim(t) == adherent.pointure)}"></option>
th:selected="${dot.isTailleOptionSelected(#strings.trim(t))}"></option>
</select>
</div>
<div th:if="${(dot.equipement.taillesDisponibles == null or dot.equipement.taillesDisponibles.trim().isEmpty())}">
<label class="block text-[9px] uppercase font-bold text-gray-400">Taille</label>
<input type="text" th:name="'taille_' + ${dot.id}" th:value="${dot.taille != null and !dot.taille.isEmpty() ? dot.taille : (adherent.tailleVetement != null ? adherent.tailleVetement : '')}" class="w-full text-xs border border-gray-300 rounded px-1 py-0.5 focus:ring-1 focus:ring-blue-500 outline-none" placeholder="Taille/Pointure">
</div>
<div th:if="${dot.equipement.couleursDisponibles != null and !dot.equipement.couleursDisponibles.trim().isEmpty()}">
<label class="block text-[9px] uppercase font-bold text-gray-400">Couleur</label>
@@ -2,7 +2,7 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Utilisateurs Connectés - AS Talange</title>
<title>Utilisateurs & Sessions - AS Talange</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
@@ -19,41 +19,99 @@
<main class="flex-1 flex flex-col h-screen overflow-hidden">
<!-- Header -->
<header class="h-16 bg-white border-b border-gray-200 flex items-center justify-between px-6">
<h2 class="text-lg font-semibold text-gray-800">Utilisateurs Connectés</h2>
<h2 class="text-lg font-semibold text-gray-800">Suivi des Connectivité & Sessions</h2>
</header>
<!-- Main section -->
<div class="flex-1 overflow-auto p-6">
<!-- Cards summary -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
<div class="bg-white p-5 rounded-xl shadow-sm border border-gray-100 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500">Total Utilisateurs</p>
<p class="text-2xl font-bold text-gray-900 mt-1" th:text="${totalCount}">0</p>
</div>
<div class="w-10 h-10 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center font-bold">
👥
</div>
</div>
<div class="bg-white p-5 rounded-xl shadow-sm border border-gray-100 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500">Sessions Actives (En ligne)</p>
<p class="text-2xl font-bold text-green-600 mt-1" th:text="${activeCount}">0</p>
</div>
<div class="w-10 h-10 rounded-lg bg-green-50 text-green-600 flex items-center justify-center font-bold">
🟢
</div>
</div>
<div class="bg-white p-5 rounded-xl shadow-sm border border-gray-100 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-500">Hors Ligne</p>
<p class="text-2xl font-bold text-gray-600 mt-1" th:text="${offlineCount}">0</p>
</div>
<div class="w-10 h-10 rounded-lg bg-gray-100 text-gray-500 flex items-center justify-center font-bold">
</div>
</div>
</div>
<!-- Header & Action -->
<div class="mb-6 flex justify-between items-center">
<h3 class="text-xl font-bold text-gray-900">
Sessions Actives (<span th:text="${activeCount}">0</span>)
Liste des Utilisateurs
</h3>
<button hx-get="/admin/sessions" hx-target="body" hx-swap="outerHTML" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors">
Rafraîchir
<button hx-get="/admin/sessions" hx-target="body" hx-swap="outerHTML" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors flex items-center space-x-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
<span>Rafraîchir</span>
</button>
</div>
<!-- User Table -->
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
<table class="w-full text-left border-collapse">
<thead>
<tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200">
<th class="py-3 px-6 font-medium text-left">Nom d'utilisateur</th>
<tr class="bg-gray-50 text-gray-500 text-xs uppercase tracking-wider border-b border-gray-200">
<th class="py-3 px-6 font-medium text-left">Utilisateur</th>
<th class="py-3 px-6 font-medium text-left">Rôle(s)</th>
<th class="py-3 px-6 font-medium text-left">Statut</th>
<th class="py-3 px-6 font-medium text-left">Dernière Connexion</th>
<th class="py-3 px-6 font-medium text-left">Dernière Déconnexion</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 text-sm">
<tr th:if="${#lists.isEmpty(activeUsers)}">
<td colspan="2" class="py-8 text-center text-gray-500">Aucun utilisateur connecté pour le moment.</td>
<tr th:if="${#lists.isEmpty(userSessions)}">
<td colspan="5" class="py-8 text-center text-gray-500">Aucun utilisateur enregistré.</td>
</tr>
<tr th:each="username : ${activeUsers}" class="hover:bg-gray-50 transition-colors">
<tr th:each="userSession : ${userSessions}" class="hover:bg-gray-50 transition-colors">
<td class="py-4 px-6 font-medium text-gray-900 flex items-center">
<div class="w-8 h-8 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center font-bold mr-3">
<span th:text="${#strings.substring(username, 0, 1).toUpperCase()}">U</span>
<div class="w-8 h-8 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center font-bold mr-3 text-xs">
<span th:text="${#strings.substring(userSession.username, 0, 1).toUpperCase()}">U</span>
</div>
<span th:text="${username}">username</span>
<span th:text="${userSession.username}">username</span>
</td>
<td class="py-4 px-6">
<span class="px-2 py-1 bg-green-100 text-green-800 text-xs font-semibold rounded-full">En ligne</span>
<span class="px-2.5 py-0.5 bg-gray-100 text-gray-700 text-xs font-medium rounded border border-gray-200" th:text="${userSession.roles}">ADMIN</span>
</td>
<td class="py-4 px-6">
<span th:if="${userSession.online}" class="inline-flex items-center px-2.5 py-1 bg-green-100 text-green-800 text-xs font-semibold rounded-full">
<span class="w-2 h-2 mr-1.5 bg-green-500 rounded-full animate-pulse"></span>
En ligne
</span>
<span th:unless="${userSession.online}" class="inline-flex items-center px-2.5 py-1 bg-gray-100 text-gray-600 text-xs font-medium rounded-full">
<span class="w-2 h-2 mr-1.5 bg-gray-400 rounded-full"></span>
Hors ligne
</span>
</td>
<td class="py-4 px-6 text-gray-600 font-mono text-xs">
<span th:text="${userSession.lastLoginAt != null ? #temporals.format(userSession.lastLoginAt, 'dd/MM/yyyy HH:mm:ss') : 'Jamais'}">01/01/2026 10:00:00</span>
</td>
<td class="py-4 px-6 text-gray-600 font-mono text-xs">
<span th:text="${userSession.lastLogoutAt != null ? #temporals.format(userSession.lastLogoutAt, 'dd/MM/yyyy HH:mm:ss') : '-'}">01/01/2026 12:00:00</span>
</td>
</tr>
</tbody>
@@ -142,7 +142,7 @@
hx-target="#paiements-table-container"
hx-select="#paiements-table-container"
hx-include="#filter-form"
th:attr="hx-vals=|{'page': ${currentPage - 1}}|"
th:attr="hx-vals=|{&quot;page&quot;: ${currentPage - 1}}|"
class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors">
Précédent
</button>
@@ -157,7 +157,7 @@
hx-target="#paiements-table-container"
hx-select="#paiements-table-container"
hx-include="#filter-form"
th:attr="hx-vals=|{'page': ${pageNum}}|"
th:attr="hx-vals=|{&quot;page&quot;: ${pageNum}}|"
th:text="${pageNum + 1}"
class="px-3 py-1 rounded transition-colors"
th:classappend="${currentPage == pageNum ? 'bg-blue-600 text-white' : 'border border-gray-300 hover:bg-gray-100'}">
@@ -172,7 +172,7 @@
hx-target="#paiements-table-container"
hx-select="#paiements-table-container"
hx-include="#filter-form"
th:attr="hx-vals=|{'page': ${currentPage + 1}}|"
th:attr="hx-vals=|{&quot;page&quot;: ${currentPage + 1}}|"
class="px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors">
Suivant
</button>
+1 -1
View File
@@ -13,7 +13,7 @@
<groupId>com.astalange</groupId>
<artifactId>as-talange-parent</artifactId>
<version>1.5</version>
<version>1.6-SNAPSHOT</version>
<packaging>pom</packaging>
<name>as-talange-parent</name>