sec(licence): restriction de l'option et de la visibilité réduction éducateur aux seuls administrateurs

This commit is contained in:
2026-08-07 23:56:03 +02:00
parent b0fe8002c5
commit 76e54de182
3 changed files with 31 additions and 13 deletions
@@ -77,8 +77,13 @@ public class LicenceController {
licence.setTypeDemande(typeDemande);
licence.setTypeLicence(typeLicence);
licence.setCommentaire(commentaire);
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
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);
licence.setReductionEducateur(Boolean.TRUE.equals(reductionEducateur));
licence.setPourcentageReductionEducateur(pourcentageReductionEducateur != null ? pourcentageReductionEducateur : 100);
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,15 +273,20 @@
th:text="${lic.etat}">Brouillon</span>
</td>
<td class="py-4 px-4 font-medium cell-tarif-global">
<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>
<div class="flex items-center space-x-1 text-xs">
<span th:if="${lic.getPrixBrut().compareTo(lic.getPrixTotal()) != 0}" class="line-through text-gray-400" th:text="${lic.getPrixBrut() + ' €'}">150.00 €</span>
<span class="text-gray-900 font-bold" th:text="${lic.getPrixTotal() + ' €'}">0.00 €</span>
<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>
<div class="flex items-center space-x-1 text-xs">
<span th:if="${lic.getPrixBrut().compareTo(lic.getPrixTotal()) != 0}" class="line-through text-gray-400" th:text="${lic.getPrixBrut() + ' €'}">150.00 €</span>
<span class="text-gray-900 font-bold" th:text="${lic.getPrixTotal() + ' €'}">0.00 €</span>
</div>
</div>
<div th:if="${!lic.reductionEducateur}">
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
</div>
</div>
<div th:if="${!lic.reductionEducateur}">
<div sec:authorize="!hasRole('ROLE_ADMIN')">
<span class="text-gray-900" th:text="${lic.getPrixTotal() + ' €'}">130.00 €</span>
</div>
</td>
@@ -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 : '-'}"></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>