feat: add licence and user remove condition check

This commit is contained in:
Thibaut Valentin 2025-07-02 19:02:46 +02:00
parent 5ce5df950f
commit 0c4b88b5cd
3 changed files with 15 additions and 4 deletions

View File

@ -112,6 +112,10 @@ public class LicenceService {
public Uni<?> deleteAskLicence(long id, Consumer<MembreModel> checkPerm) { public Uni<?> deleteAskLicence(long id, Consumer<MembreModel> checkPerm) {
return repository.findById(id) return repository.findById(id)
.call(licenceModel -> Mutiny.fetch(licenceModel.getMembre()).invoke(checkPerm)) .call(licenceModel -> Mutiny.fetch(licenceModel.getMembre()).invoke(checkPerm))
.invoke(Unchecked.consumer(licenceModel -> {
if (licenceModel.isValidate())
throw new DBadRequestException("Impossible de supprimer une licence déjà validée");
}))
.chain(__ -> Panache.withTransaction(() -> repository.deleteById(id))); .chain(__ -> Panache.withTransaction(() -> repository.deleteById(id)));
} }
} }

View File

@ -368,6 +368,12 @@ public class MembreService {
if (!securityCtx.isInClubGroup(membreModel.getClub().getId())) if (!securityCtx.isInClubGroup(membreModel.getClub().getId()))
throw new DForbiddenException(); throw new DForbiddenException();
})) }))
.invoke(Unchecked.consumer(membreModel -> {
if (membreModel.getLicence() != null) {
throw new DBadRequestException(
"Impossible de supprimer un membre qui a déjà un numéro de licence");
}
}))
.call(membreModel -> licenceRepository.find("membre = ?1", membreModel).count() .call(membreModel -> licenceRepository.find("membre = ?1", membreModel).count()
.invoke(Unchecked.consumer(l -> { .invoke(Unchecked.consumer(l -> {
if (l > 0) if (l > 0)

View File

@ -59,10 +59,11 @@ export function MemberPage() {
<LoadingProvider><SelectCard/></LoadingProvider> <LoadingProvider><SelectCard/></LoadingProvider>
</div> </div>
</div> </div>
<div className="col" style={{textAlign: 'right', marginTop: '1em'}}> {data.licence == null &&
<button className="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#confirm-delete">Supprimer le compte <div className="col" style={{textAlign: 'right', marginTop: '1em'}}>
</button> <button className="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#confirm-delete">Supprimer le compte
</div> </button>
</div>}
<ConfirmDialog title="Supprimer le compte" message="Êtes-vous sûr de vouloir supprimer ce compte ?" <ConfirmDialog title="Supprimer le compte" message="Êtes-vous sûr de vouloir supprimer ce compte ?"
onConfirm={handleRm}/> onConfirm={handleRm}/>
</div> </div>