diff --git a/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java b/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java index 6622ca95..1c06ccaf 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/UserDao.java @@ -222,21 +222,23 @@ public class UserDao { } } } + private void validateDuplicateEmail(String email, String hubUuid, String roleType) { - Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries( - email, hubUuid, RoleStatusEnum.ROLE_BENEFICIARY.getValue()); + String beneficiaryRoleType = RoleStatusEnum.ROLE_BENEFICIARY.getValue(); - Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries( - email, hubUuid, RoleStatusEnum.ROLE_BENEFICIARY.getValue()); + if (beneficiaryRoleType.equals(roleType)) { + Boolean beneficiaryExistsInHub = userRepository.existsByEmailIgnoreCaseForBeneficiaries( + email, hubUuid, beneficiaryRoleType); - if (Boolean.TRUE.equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue().equals(roleType))) { - if (beneficiaryExistsInHub) { + if (Boolean.TRUE.equals(beneficiaryExistsInHub)) { throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS)); } - } - else { - if (existsForNonBeneficiaries) { + } else { + Boolean existsForNonBeneficiaries = userRepository.existsByEmailIgnoreCaseForNonBeneficiaries( + email, hubUuid, beneficiaryRoleType); + + if (Boolean.TRUE.equals(existsForNonBeneficiaries)) { throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.EMAIL_ALREADY_EXISTS)); } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java index ae41b9b1..ab00d3e0 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java @@ -33,24 +33,28 @@ public interface UserRepository extends JpaRepository { Optional findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); - Boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); +// Boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); - @Query("SELECT COUNT(u) > 0 " + - "FROM UserEntity u " + - "WHERE u.email = :email " + - "AND u.hub.uniqueUuid = :hubUuid " + - "AND u.roleEntity.roleType <> :beneficiaryRoleType") - Boolean existsByEmailIgnoreCaseForNonBeneficiaries(@Param("email") String email, - @Param("hubUuid") String hubUuid, - @Param("beneficiaryRoleType") String beneficiaryRoleType); + @Query("SELECT COUNT(u) > 0 " + + "FROM UserEntity u " + + "WHERE LOWER(u.email) = LOWER(:email) " + + "AND u.hub.uniqueUuid = :hubUuid " + + "AND u.roleEntity.roleType <> :beneficiaryRoleType") + Boolean existsByEmailIgnoreCaseForNonBeneficiaries(@Param("email") String email, + @Param("hubUuid") String hubUuid, + @Param("beneficiaryRoleType") String beneficiaryRoleType); - @Query("SELECT CASE WHEN COUNT(u) > 0 THEN true ELSE false END " + - "FROM UserEntity u " + - "WHERE LOWER(u.email) = LOWER(:email) AND u.hub.uniqueUuid = :hubUuid " + - "AND u.roleEntity.roleType = :beneficiaryRoleType") - Boolean existsByEmailIgnoreCaseForBeneficiaries(String email, String hubUuid, String beneficiaryRoleType); + @Query("SELECT COUNT(u) > 0 " + + "FROM UserEntity u " + + "WHERE LOWER(u.email) = LOWER(:email) " + + "AND u.hub.uniqueUuid = :hubUuid " + + "AND u.roleEntity.roleType = :beneficiaryRoleType") + Boolean existsByEmailIgnoreCaseForBeneficiaries(@Param("email") String email, + @Param("hubUuid") String hubUuid, + @Param("beneficiaryRoleType") String beneficiaryRoleType); - // existsByBebooleanneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); + + boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); List findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId); diff --git a/src/main/resources/db/dump/insert_system_email_template_for_reset_password_28_11_2024.sql b/src/main/resources/db/dump/insert_system_email_template_for_reset_password_28_11_2024.sql index facb4fdf..927345b0 100644 --- a/src/main/resources/db/dump/insert_system_email_template_for_reset_password_28_11_2024.sql +++ b/src/main/resources/db/dump/insert_system_email_template_for_reset_password_28_11_2024.sql @@ -20,12 +20,7 @@ VALUES

Gentile {{user_name}},

-

Hai richiesto di reimpostare la tua password. Puoi farlo cliccando sul link sottostante:

- - - - - {{reset_password_link}} +

Hai richiesto di reimpostare la tua password.