rajah 6 kuukautta sitten
vanhempi
commit
2f6cd02e0d

+ 17 - 6
src/main/java/fr/triplea/demovote/dao/ParticipantRepository.java

@@ -18,7 +18,16 @@ public interface ParticipantRepository extends JpaRepository<Participant, Intege
   
   @NativeQuery("SELECT DISTINCT p.* FROM vote.participants AS p WHERE p.numero_participant = :id AND p.flag_actif IS TRUE ")
   Participant findById(@Param("id") int id);
-
+  
+  @NativeQuery("SELECT DISTINCT "
+      + "COUNT(p.*) AS nombre "
+      + "FROM vote.participants AS p "
+      + "WHERE p.flag_actif IS TRUE "
+      + "AND ((:nom IS NULL) OR (UPPER(p.nom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.prenom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.pseudonyme) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.groupe) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.email) LIKE CONCAT('%', :nom, '%'))) "
+      + "AND ((:statut = 0) OR (:statut = 1 AND p.statut = 'EN_ATTENTE'::vote.statut_participant)) "
+      + "AND ((:arrive = 0) OR (:arrive = 1 AND p.flag_arrive = FALSE) OR (:arrive = 2 AND p.flag_arrive = TRUE)) ")
+  Integer count(@Param("nom") String nom, @Param("statut") int statut, @Param("arrive") int arrive);
+  
   @NativeQuery("SELECT DISTINCT "
       + "p.numero_participant, "
       + "p.nom, "
@@ -37,9 +46,10 @@ public interface ParticipantRepository extends JpaRepository<Participant, Intege
       + "AND ((:nom IS NULL) OR (UPPER(p.nom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.prenom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.pseudonyme) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.groupe) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.email) LIKE CONCAT('%', :nom, '%'))) "
       + "AND ((:statut = 0) OR (:statut = 1 AND p.statut = 'EN_ATTENTE'::vote.statut_participant)) "
       + "AND ((:arrive = 0) OR (:arrive = 1 AND p.flag_arrive = FALSE) OR (:arrive = 2 AND p.flag_arrive = TRUE)) "
-      + "ORDER BY p.nom ASC, p.prenom ASC, p.pseudonyme ASC ")
-  List<ParticipantList> getListOrderedByNom(@Param("nom") String nom, @Param("statut") int statut, @Param("arrive") int arrive);
-
+      + "ORDER BY p.nom ASC, p.prenom ASC, p.pseudonyme ASC "
+      + "LIMIT :limite OFFSET :debut ")
+  List<ParticipantList> getPageOrderedByNom(@Param("nom") String nom, @Param("statut") int statut, @Param("arrive") int arrive, @Param("debut") int debut, @Param("limite") Integer limite);
+  
   @NativeQuery("SELECT DISTINCT "
       + "p.numero_participant, "
       + "p.nom, "
@@ -58,8 +68,9 @@ public interface ParticipantRepository extends JpaRepository<Participant, Intege
       + "AND ((:nom IS NULL) OR (UPPER(p.nom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.prenom) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.pseudonyme) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.groupe) LIKE CONCAT('%', :nom, '%')) OR (UPPER(p.email) LIKE CONCAT('%', :nom, '%'))) "
       + "AND ((:statut = 0) OR (:statut = 1 AND p.statut = 'EN_ATTENTE'::vote.statut_participant)) "
       + "AND ((:arrive = 0) OR (:arrive = 1 AND p.flag_arrive = FALSE) OR (:arrive = 2 AND p.flag_arrive = TRUE)) "
-      + "ORDER BY p.numero_participant ASC ")
-  List<ParticipantList> getListOrderedByDateInscription(@Param("nom") String nom, @Param("statut") int statut, @Param("arrive") int arrive);
+      + "ORDER BY p.numero_participant ASC "
+      + "LIMIT :limite OFFSET :debut ")
+  List<ParticipantList> getPageOrderedByDateInscription(@Param("nom") String nom, @Param("statut") int statut, @Param("arrive") int arrive, @Param("debut") int debut, @Param("limite") Integer limite);
 
   @NativeQuery("SELECT DISTINCT p.* FROM vote.participants AS p WHERE p.flag_actif IS TRUE ORDER BY p.nom ASC, p.prenom ASC, p.pseudonyme ASC ")
   List<Participant> findAll();

+ 35 - 0
src/main/java/fr/triplea/demovote/dto/Pagination.java

@@ -0,0 +1,35 @@
+package fr.triplea.demovote.dto;
+
+public class Pagination 
+{
+
+  /** nombre d'éléments */
+  int nombreElements = 0;
+  /** nombre d'éléments dans une page */
+  int taillePage = 100;
+  /** nombre de pages */
+  int nombrePages = 1;
+  /** index de page, débute à 0 */
+  int pageCourante = 0;
+
+  public Pagination(int nombreElements, int taillePage, int nombrePage, int pageCourante) 
+  {
+    this.nombreElements = nombreElements;
+    this.taillePage = taillePage;
+    this.nombrePages = nombrePage;
+    this.pageCourante = pageCourante;
+  }
+
+  public void setNombreElements(int nombreElements) { this.nombreElements = nombreElements; }
+  public int getNombreElements() { return nombreElements; }
+
+  public int getTaillePage() { return taillePage; }
+  public void setTaillePage(int taillePage) { this.taillePage = taillePage; }
+  
+  public void setNombrePages(int nombrePage) { this.nombrePages = nombrePage; }
+  public int getNombrePages() { return nombrePages; }
+  
+  public void setPageCourante(int pageCourante) { this.pageCourante = pageCourante; }
+  public int getPageCourante() { return pageCourante; }
+
+}

+ 49 - 28
src/main/java/fr/triplea/demovote/web/controller/AuthController.java

@@ -25,6 +25,7 @@ import fr.triplea.demovote.dto.JourneesTransfer;
 import fr.triplea.demovote.dto.RefreshTokenTransfer;
 import fr.triplea.demovote.dto.UserCredentials;
 import fr.triplea.demovote.model.Participant;
+import fr.triplea.demovote.model.ParticipantStatut;
 import fr.triplea.demovote.model.RefreshToken;
 import fr.triplea.demovote.model.Role;
 import fr.triplea.demovote.security.MyUserDetailsService;
@@ -97,35 +98,55 @@ public class AuthController
       
       if (passwordEncoder.matches(pass, userDetails.getPassword()))
       {
-        // TODO : restreindre la connexion aux participants avec flag 'arrivés' à true ?
-        
-        SecurityContextHolder.getContext().setAuthentication(authentication);
-        
-        String token = jwtTokenUtil.generateJwtToken(authentication);
-        
-        refreshTokenService.deleteByNumeroParticipant(found.getNumeroParticipant());
-        
-        RefreshToken refreshToken = refreshTokenService.createRefreshToken(found.getNumeroParticipant());
-                
-        uc = new UserCredentials();
-        
-        uc.setNumeroParticipant(found.getNumeroParticipant());
-        uc.setUsername(usrn);
-        uc.setPassword("<success@auth>");
-        uc.setNom(found.getNom());
-        uc.setPrenom(found.getPrenom());
-        uc.setDelaiAvantDeconnexion(found.getDelaiDeconnexion());
-        uc.setAccessToken(token);
-        uc.setRefreshToken(refreshToken.getToken());
-        uc.setErreur("");
-
-        List<Role> roles = found.getRoles();
+        if (found.getStatut().equals(ParticipantStatut.EN_ATTENTE))
+        {
+          // si le règlement est toujours en attente, il faut aller à l'accueil pour régulariser
+          
+          uc = new UserCredentials();
+          
+          uc.setNumeroParticipant(0);
+          uc.setUsername("");
+          uc.setPassword("");
+          uc.setNom("");
+          uc.setPrenom("");
+          uc.setDelaiAvantDeconnexion(15);
+          uc.setAccessToken("");
+          uc.setRefreshToken("");
+          uc.setRole("");
+          uc.setErreur(messageSource.getMessage("auth.user.notpaid", null, locale));
          
-        if (!(uc.hasRole())) { for (Role role : roles) { if (role.isRole("ADMIN")) { uc.setRole("ADMIN"); } } }
-        if (!(uc.hasRole())) { for (Role role : roles) { if (role.isRole("ORGA")) { uc.setRole("ORGA"); } } }
-        if (!(uc.hasRole())) { uc.setRole("USER"); }
-
-        return ResponseEntity.ok(uc);
+          return ResponseEntity.ok(uc);
+        }
+        else
+        {
+          SecurityContextHolder.getContext().setAuthentication(authentication);
+          
+          String token = jwtTokenUtil.generateJwtToken(authentication);
+          
+          refreshTokenService.deleteByNumeroParticipant(found.getNumeroParticipant());
+          
+          RefreshToken refreshToken = refreshTokenService.createRefreshToken(found.getNumeroParticipant());
+                  
+          uc = new UserCredentials();
+          
+          uc.setNumeroParticipant(found.getNumeroParticipant());
+          uc.setUsername(usrn);
+          uc.setPassword("<success@auth>");
+          uc.setNom(found.getNom());
+          uc.setPrenom(found.getPrenom());
+          uc.setDelaiAvantDeconnexion(found.getDelaiDeconnexion());
+          uc.setAccessToken(token);
+          uc.setRefreshToken(refreshToken.getToken());
+          uc.setErreur("");
+
+          List<Role> roles = found.getRoles();
+           
+          if (!(uc.hasRole())) { for (Role role : roles) { if (role.isRole("ADMIN")) { uc.setRole("ADMIN"); } } }
+          if (!(uc.hasRole())) { for (Role role : roles) { if (role.isRole("ORGA")) { uc.setRole("ORGA"); } } }
+          if (!(uc.hasRole())) { uc.setRole("USER"); }
+
+          return ResponseEntity.ok(uc);
+        }
       }
       else
       {

+ 54 - 5
src/main/java/fr/triplea/demovote/web/controller/ParticipantController.java

@@ -31,7 +31,9 @@ import org.springframework.web.servlet.LocaleResolver;
 
 import fr.triplea.demovote.dao.ParticipantRepository;
 import fr.triplea.demovote.dao.RoleRepository;
+import fr.triplea.demovote.dao.VariableRepository;
 import fr.triplea.demovote.dto.MessagesTransfer;
+import fr.triplea.demovote.dto.Pagination;
 import fr.triplea.demovote.dto.ParticipantList;
 import fr.triplea.demovote.dto.ParticipantOptionList;
 import fr.triplea.demovote.dto.ParticipantTransfer;
@@ -45,13 +47,16 @@ import jakarta.servlet.http.HttpServletRequest;
 @RequestMapping("/participant")
 public class ParticipantController 
 {
-  
+
   @Autowired
   private RoleRepository roleRepository;
 
   @Autowired
   private ParticipantRepository participantRepository;
   
+  @Autowired
+  private VariableRepository variableRepository;
+  
   @Autowired
   private PasswordEncoder passwordEncoder;
 
@@ -64,15 +69,59 @@ public class ParticipantController
 
   @GetMapping(value = "/list")
   @PreAuthorize("hasRole('ORGA')")
-  public List<ParticipantList> getList(@RequestParam("nom") String filtreNom, @RequestParam("statut") int filtreStatut, @RequestParam("arrive") int filtreArrive, @RequestParam("tri") int choixTri) 
+  public List<ParticipantList> getList(
+      @RequestParam("nom") String filtreNom, 
+      @RequestParam("statut") int filtreStatut, 
+      @RequestParam("arrive") int filtreArrive, 
+      @RequestParam("tri") int choixTri, 
+      @RequestParam(name="page", defaultValue="0") int numeroPage, 
+      @RequestParam(name="size", defaultValue="0") Integer nombreParPage
+      ) 
   { 
     if (filtreNom != null) { if (filtreNom.isBlank()) { filtreNom = null; } else { filtreNom = filtreNom.trim().toUpperCase(); } }
     
-    if (choixTri == 1) { return participantRepository.getListOrderedByDateInscription(filtreNom, filtreStatut, filtreArrive); }
+    if (nombreParPage == 0) { try { nombreParPage = Integer.parseInt(variableRepository.findByTypeAndCode("Navigation", "LISTE_PARTICIPANTS_MAX")); } catch(Exception e) { nombreParPage = null; } }
+    
+    if ((nombreParPage == null) || (nombreParPage == 0)) { numeroPage = 0; }
+    
+    int offset = 0;
+    
+    if (numeroPage > 0) { offset = ((numeroPage * nombreParPage) + 1); }
+    
+    if (choixTri == 1) 
+    { 
+      return participantRepository.getPageOrderedByDateInscription(filtreNom, filtreStatut, filtreArrive, offset, nombreParPage); 
+    }
+    else 
+    {
+      return participantRepository.getPageOrderedByNom(filtreNom, filtreStatut, filtreArrive, offset, nombreParPage);
+    }
+  }
+
+  @GetMapping(value = "/pagination")
+  @PreAuthorize("hasRole('ORGA')")
+  public Pagination getCount(
+      @RequestParam("nom") String filtreNom, 
+      @RequestParam("statut") int filtreStatut, 
+      @RequestParam("arrive") int filtreArrive, 
+      @RequestParam(name="page", defaultValue="0") int numeroPage
+      ) 
+  { 
+    if (filtreNom != null) { if (filtreNom.isBlank()) { filtreNom = null; } else { filtreNom = filtreNom.trim().toUpperCase(); } }
+    
+    int nombreParPage = 100;
+    
+    try { nombreParPage = Integer.parseInt(variableRepository.findByTypeAndCode("Navigation", "LISTE_PARTICIPANTS_MAX")); } catch(Exception e) { nombreParPage = 100; }
+
+    int nombreElements = participantRepository.count(filtreNom, filtreStatut, filtreArrive);
+     
+    int nombrePages = 0;
+    
+    int decompte = nombreElements; while (decompte > 0) { nombrePages++; decompte -= nombreParPage; }
     
-    // TODO : pagination pour réduire affichage
+    numeroPage = Math.max(0, Math.min(numeroPage, nombrePages - 1));
     
-    return participantRepository.getListOrderedByNom(filtreNom, filtreStatut, filtreArrive);
+    return new Pagination(nombreElements, nombreParPage, nombrePages, numeroPage);
   }
 
   

+ 1 - 0
src/main/resources/langs/messages_en.properties

@@ -1,5 +1,6 @@
 auth.password.mismatches=The password does not match any entrant's password.
 auth.user.notfound=The nickname does not seem to be used by any entrant.
+auth.user.notpaid=Nickname and password are good. But access is not granted yet, your status is still awaiting for payment. Please go to reception at the entrance to complete formalities.
 
 refreshtoken.notfound=the currrent RefreshToken is not present in the database.
 refreshtoken.expired=the current RefreshToken has expired. Please re-sign in.

+ 1 - 0
src/main/resources/langs/messages_fr.properties

@@ -1,5 +1,6 @@
 auth.password.mismatches=Le mot de passe ne correspond pas à ce participant.
 auth.user.notfound=Le pseudonyme ne semble pas être celui d'un participant.
+auth.user.notpaid=Pseudonyme et mot de passe correct. Cependant, l'accès n'est pas pour l'instant permis, votre statut est toujours en attente : merci d'aller à l'accueil effectuer le réglement.
 
 refreshtoken.notfound=ce RefreshToken introuvable dans la base de données.
 refreshtoken.expired=ce RefreshToken a expiré. Merci de vous reconnecter.