sec(licence): restriction de l'option et de la visibilité réduction éducateur aux seuls administrateurs
This commit is contained in:
@@ -77,8 +77,13 @@ public class LicenceController {
|
||||
licence.setTypeDemande(typeDemande);
|
||||
licence.setTypeLicence(typeLicence);
|
||||
licence.setCommentaire(commentaire);
|
||||
if (isUserAdmin()) {
|
||||
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
|
||||
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
|
||||
} else {
|
||||
licence.setReductionEducateur(false);
|
||||
licence.setPourcentageReductionEducateur(100);
|
||||
}
|
||||
|
||||
if (equipeId != null) {
|
||||
Equipe equipe = equipeRepository.findById(equipeId)
|
||||
@@ -120,8 +125,10 @@ public class LicenceController {
|
||||
licence.setTypeDemande(typeDemande);
|
||||
licence.setTypeLicence(typeLicence);
|
||||
licence.setCommentaire(commentaire);
|
||||
if (isUserAdmin()) {
|
||||
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
|
||||
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
|
||||
}
|
||||
|
||||
if (equipeId != null) {
|
||||
Equipe equipe = equipeRepository.findById(equipeId)
|
||||
@@ -270,4 +277,10 @@ public class LicenceController {
|
||||
return cb.and(predicates.toArray(new jakarta.persistence.criteria.Predicate[0]));
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isUserAdmin() {
|
||||
org.springframework.security.core.Authentication auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
|
||||
return auth != null && auth.getAuthorities().stream()
|
||||
.anyMatch(a -> a.getAuthority().equals("ROLE_ADMIN") || a.getAuthority().equals("ADMIN"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +273,7 @@
|
||||
th:text="${lic.etat}">Brouillon</span>
|
||||
</td>
|
||||
<td class="py-4 px-4 font-medium cell-tarif-global">
|
||||
<div sec:authorize="hasRole('ROLE_ADMIN')">
|
||||
<div th:if="${lic.reductionEducateur}" class="flex flex-col">
|
||||
<span class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-2 py-0.5 rounded-full inline-block w-max mb-0.5"
|
||||
th:text="'Éducateur (-' + ${lic.pourcentageReductionEducateur != null ? lic.pourcentageReductionEducateur : 100} + '%)'">Éducateur (-100%)</span>
|
||||
@@ -284,6 +285,10 @@
|
||||
<div th:if="${!lic.reductionEducateur}">
|
||||
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
|
||||
</div>
|
||||
</div>
|
||||
<div sec:authorize="!hasRole('ROLE_ADMIN')">
|
||||
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="py-4 px-4 font-semibold cell-reste-payer"
|
||||
th:classappend="${lic.getResteAPayer().compareTo(T(java.math.BigDecimal).ZERO) == 0 ? 'text-green-600' : 'text-red-600'}"
|
||||
@@ -579,7 +584,7 @@
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Commentaire</label>
|
||||
<textarea id="licenceCommentaireInput" name="commentaire" rows="3" class="w-full border border-gray-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-blue-500 outline-none" placeholder="Commentaire optionnel..."></textarea>
|
||||
</div>
|
||||
<div class="bg-amber-50 p-3 rounded-lg border border-amber-200">
|
||||
<div sec:authorize="hasRole('ROLE_ADMIN')" class="bg-amber-50 p-3 rounded-lg border border-amber-200">
|
||||
<label class="flex items-center space-x-2 cursor-pointer select-none">
|
||||
<input type="checkbox" id="reductionEducateurInput" name="reductionEducateur" value="true" onchange="toggleReductionPourcentageVisibility()" class="w-4 h-4 text-amber-600 border-gray-300 rounded focus:ring-amber-500">
|
||||
<span class="text-sm font-semibold text-amber-900">Enfant d'éducateur / Réduction</span>
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<td class="py-3 px-4 text-gray-600 font-mono" th:text="${licence.numeroLicence != null ? licence.numeroLicence : '-'}">N°</td>
|
||||
<td class="py-3 px-4 text-gray-600">
|
||||
<div th:text="${licence.typeDemande != null ? licence.typeDemande : '-'}">Type</div>
|
||||
<span th:if="${licence.reductionEducateur}" class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded-full inline-block mt-0.5" th:text="'Éducateur (-' + ${licence.pourcentageReductionEducateur} + '%)'">Éducateur (-100%)</span>
|
||||
<span sec:authorize="hasRole('ROLE_ADMIN')" th:if="${licence.reductionEducateur}" class="text-[10px] font-bold text-amber-700 bg-amber-50 border border-amber-200 px-1.5 py-0.5 rounded-full inline-block mt-0.5" th:text="'Éducateur (-' + ${licence.pourcentageReductionEducateur} + '%)'">Éducateur (-100%)</span>
|
||||
</td>
|
||||
<td class="py-3 px-4 text-gray-600" th:text="${licence.adherent.email != null ? licence.adherent.email : '-'}">Email</td>
|
||||
<td class="py-3 px-4 text-gray-600" th:text="${licence.etat != null ? licence.etat : '-'}">Etat</td>
|
||||
|
||||
Reference in New Issue
Block a user