commit
ee6d41c155
@ -18,7 +18,7 @@ import java.util.Map;
|
||||
|
||||
@Entity
|
||||
@Table(name = "club")
|
||||
public class ClubModel {
|
||||
public class ClubModel implements LoggableModel {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Schema(description = "Identifiant du club", example = "1")
|
||||
@ -70,4 +70,14 @@ public class ClubModel {
|
||||
@OneToMany(mappedBy = "club", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
@Schema(description = "Liste des affiliations du club (optionnel)")
|
||||
List<AffiliationModel> affiliations;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogModel.ObjectType getObjectType() {
|
||||
return LogModel.ObjectType.Club;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ public class LicenceModel {
|
||||
@Schema(description = "Le membre de la licence. (optionnel)")
|
||||
MembreModel membre;
|
||||
|
||||
Long club_id;
|
||||
|
||||
@Schema(description = "La saison de la licence.", example = "2025")
|
||||
int saison;
|
||||
|
||||
|
||||
45
src/main/java/fr/titionfire/ffsaf/data/model/LogModel.java
Normal file
45
src/main/java/fr/titionfire/ffsaf/data/model/LogModel.java
Normal file
@ -0,0 +1,45 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
|
||||
@Entity
|
||||
@Table(name = "log")
|
||||
public class LogModel {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Long id;
|
||||
|
||||
String subject;
|
||||
|
||||
Date dateTime;
|
||||
|
||||
ActionType action;
|
||||
|
||||
ObjectType object;
|
||||
|
||||
Long target_id;
|
||||
|
||||
String target_name;
|
||||
|
||||
String message;
|
||||
|
||||
public enum ActionType {
|
||||
ADD, REMOVE, UPDATE
|
||||
}
|
||||
|
||||
public enum ObjectType {
|
||||
Membre, Affiliation, Licence, Club, Competition, Register
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
public interface LoggableModel {
|
||||
Long getId();
|
||||
String getObjectName();
|
||||
LogModel.ObjectType getObjectType();
|
||||
}
|
||||
@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "membre")
|
||||
public class MembreModel {
|
||||
public class MembreModel implements LoggableModel {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@ -72,4 +72,14 @@ public class MembreModel {
|
||||
@OneToMany(mappedBy = "membre", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
@Schema(description = "Les licences du membre. (optionnel)")
|
||||
List<LicenceModel> licences;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return fname + " " + lname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogModel.ObjectType getObjectType() {
|
||||
return LogModel.ObjectType.Membre;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package fr.titionfire.ffsaf.data.repository;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LogModel;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class LogRepository implements PanacheRepositoryBase<LogModel, Long> {
|
||||
}
|
||||
@ -58,6 +58,9 @@ public class AffiliationService {
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
@ConfigProperty(name = "notif.affRequest.mail")
|
||||
List<String> mails;
|
||||
|
||||
public Uni<List<AffiliationRequestModel>> getAllReq() {
|
||||
return repositoryRequest.listAll();
|
||||
}
|
||||
@ -140,7 +143,7 @@ public class AffiliationService {
|
||||
}
|
||||
|
||||
public Uni<String> save(AffiliationRequestForm form) {
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
// noinspection ResultOfMethodCallIgnored,ReactiveStreamsUnusedPublisher
|
||||
return pre_save(form, true)
|
||||
.chain(model -> Panache.withTransaction(() -> repositoryRequest.persist(model)))
|
||||
.onItem()
|
||||
@ -149,6 +152,16 @@ public class AffiliationService {
|
||||
.onItem()
|
||||
.invoke(model -> Uni.createFrom().future(Utils.replacePhoto(model.getId(), form.getStatus(), media,
|
||||
"aff_request/status")))
|
||||
.call(model -> reactiveMailer.send(
|
||||
Mail.withText("no-reply@ffsaf.fr",
|
||||
"[NOTIF] FFSAF - Nouvelle demande d'affiliation",
|
||||
String.format(
|
||||
"""
|
||||
Une nouvelle demande d'affiliation a été déposée sur l'intranet pour le club: %s.
|
||||
""", model.getName())
|
||||
).setFrom("FFSAF <no-reply@ffsaf.fr>")
|
||||
.addBcc(mails.toArray(String[]::new))
|
||||
))
|
||||
.map(__ -> "Ok");
|
||||
}
|
||||
|
||||
@ -250,7 +263,7 @@ public class AffiliationService {
|
||||
.call(l1 -> l1 != null && l1.stream().anyMatch(l -> l.getSaison() == saison) ?
|
||||
Uni.createFrom().nullItem() :
|
||||
Panache.withTransaction(() -> licenceRepository.persist(
|
||||
new LicenceModel(null, m, saison, null, true)))));
|
||||
new LicenceModel(null, m, club.getId(), saison, null, true)))));
|
||||
}
|
||||
|
||||
public Uni<?> accept(AffiliationRequestSaveForm form) {
|
||||
@ -392,8 +405,27 @@ public class AffiliationService {
|
||||
return Panache.withTransaction(() -> repository.deleteById(id));
|
||||
}
|
||||
|
||||
public Uni<?> deleteReqAffiliation(long id) {
|
||||
return Panache.withTransaction(() -> repositoryRequest.deleteById(id))
|
||||
public Uni<?> deleteReqAffiliation(long id, String reason) {
|
||||
return repositoryRequest.findById(id)
|
||||
.call(aff -> reactiveMailer.send(
|
||||
Mail.withText(aff.getM1_email(),
|
||||
"FFSAF - Votre demande d'affiliation a été rejetée.",
|
||||
String.format(
|
||||
"""
|
||||
Bonjour,
|
||||
|
||||
Votre demande d'affiliation pour le club %s a été rejetée pour la/les raison(s) suivante(s):
|
||||
%s
|
||||
|
||||
Si vous rencontrez un problème ou si vous avez des questions, n'hésitez pas à nous contacter à l'adresse contact@ffsaf.fr.
|
||||
|
||||
Cordialement,
|
||||
L'équipe de la FFSAF
|
||||
""", aff.getName(), reason)
|
||||
).setFrom("FFSAF <no-reply@ffsaf.fr>").setReplyTo("contact@ffsaf.fr")
|
||||
.addTo(aff.getM2_email(), aff.getM3_email())
|
||||
))
|
||||
.chain(aff -> Panache.withTransaction(() -> repositoryRequest.delete(aff)))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "aff_request/logo"))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "aff_request/status"));
|
||||
}
|
||||
|
||||
@ -34,10 +34,7 @@ import jakarta.inject.Inject;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
|
||||
@ -61,6 +58,9 @@ public class ClubService {
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
@Inject
|
||||
LoggerService ls;
|
||||
|
||||
public SimpleClubModel findByIdOptionalClub(long id) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(
|
||||
() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleClubModel::fromModel)));
|
||||
@ -78,8 +78,10 @@ public class ClubService {
|
||||
|
||||
public Uni<?> setClubId(Long id, String id1) {
|
||||
return repository.findById(id).chain(clubModel -> {
|
||||
ls.logChange("KC UUID", clubModel.getClubId(), id1, clubModel);
|
||||
clubModel.setClubId(id1);
|
||||
return Panache.withTransaction(() -> repository.persist(clubModel));
|
||||
return Panache.withTransaction(() -> repository.persist(clubModel))
|
||||
.call(() -> ls.append());
|
||||
});
|
||||
}
|
||||
|
||||
@ -156,18 +158,26 @@ public class ClubService {
|
||||
.map(MembreModel::getClub)
|
||||
.call(club -> Mutiny.fetch(club.getContact()))
|
||||
.chain(Unchecked.function(club -> {
|
||||
ls.logChange("Contact interne", club.getContact_intern(), form.getContact_intern(), club);
|
||||
club.setContact_intern(form.getContact_intern());
|
||||
ls.logChange("Adresse administrative", club.getAddress(), form.getAddress(), club);
|
||||
club.setAddress(form.getAddress());
|
||||
|
||||
try {
|
||||
if (!Objects.equals(club.getContact(), MAPPER.readValue(form.getContact(), typeRef)))
|
||||
ls.logUpdate("Contact(s)...", club);
|
||||
club.setContact(MAPPER.readValue(form.getContact(), typeRef));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new DBadRequestException("Erreur de format des contacts");
|
||||
}
|
||||
|
||||
ls.logChange("Lieux d'entrainements", club.getTraining_location(), form.getTraining_location(),
|
||||
club);
|
||||
club.setTraining_location(form.getTraining_location());
|
||||
ls.logChange("Horaires d'entrainements", club.getTraining_day_time(), form.getTraining_day_time(),
|
||||
club);
|
||||
club.setTraining_day_time(form.getTraining_day_time());
|
||||
return Panache.withTransaction(() -> repository.persist(club));
|
||||
return Panache.withTransaction(() -> repository.persist(club)).call(() -> ls.append());
|
||||
}))
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
@ -183,21 +193,32 @@ public class ClubService {
|
||||
m.setInternational(input.isInternational());
|
||||
|
||||
if (!input.isInternational()) {
|
||||
ls.logChange("Lieux d'entrainements", m.getTraining_location(), input.getTraining_location(),
|
||||
m);
|
||||
m.setTraining_location(input.getTraining_location());
|
||||
ls.logChange("Horaires d'entrainements", m.getTraining_day_time(), input.getTraining_day_time(),
|
||||
m);
|
||||
m.setTraining_day_time(input.getTraining_day_time());
|
||||
ls.logChange("Contact interne", m.getContact_intern(), input.getContact_intern(), m);
|
||||
m.setContact_intern(input.getContact_intern());
|
||||
ls.logChange("N° RNA", m.getRNA(), input.getRna(), m);
|
||||
m.setRNA(input.getRna());
|
||||
if (input.getSiret() != null && !input.getSiret().isBlank())
|
||||
if (input.getSiret() != null && !input.getSiret().isBlank()) {
|
||||
ls.logChange("N° SIRET", m.getSIRET(), input.getSiret(), m);
|
||||
m.setSIRET(Long.parseLong(input.getSiret()));
|
||||
}
|
||||
ls.logChange("Adresse administrative", m.getAddress(), input.getAddress(), m);
|
||||
m.setAddress(input.getAddress());
|
||||
|
||||
try {
|
||||
if (!Objects.equals(m.getContact(), MAPPER.readValue(input.getContact(), typeRef)))
|
||||
ls.logUpdate("Contact(s)...", m);
|
||||
m.setContact(MAPPER.readValue(input.getContact(), typeRef));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new DBadRequestException("Erreur de format des contacts");
|
||||
}
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(m));
|
||||
return Panache.withTransaction(() -> repository.persist(m)).call(() -> ls.append());
|
||||
}))
|
||||
.invoke(membreModel -> SReqClub.sendIfNeed(serverCustom.clients,
|
||||
SimpleClubModel.fromModel(membreModel)))
|
||||
@ -233,6 +254,7 @@ public class ClubService {
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(clubModel));
|
||||
})
|
||||
.call(clubModel -> ls.logAAdd(clubModel))
|
||||
.call(clubModel -> keycloakService.getGroupFromClub(clubModel)) // create group in keycloak
|
||||
.invoke(clubModel -> SReqClub.sendAddIfNeed(serverCustom.clients, SimpleClubModel.fromModel(clubModel)))
|
||||
.map(ClubModel::getId);
|
||||
@ -255,6 +277,7 @@ public class ClubService {
|
||||
.call(clubModel -> (clubModel.getClubId() == null) ? Uni.createFrom()
|
||||
.voidItem() : keycloakService.removeClubGroup(clubModel.getClubId()))
|
||||
.invoke(membreModel -> SReqClub.sendRmIfNeed(serverCustom.clients, id))
|
||||
.call(clubModel -> ls.logADelete(clubModel))
|
||||
.chain(clubModel -> Panache.withTransaction(() -> repository.delete(clubModel)))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "ppClub"))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "clubStatus"));
|
||||
|
||||
@ -53,6 +53,7 @@ public class LicenceService {
|
||||
return combRepository.findById(id).chain(membreModel -> {
|
||||
LicenceModel model = new LicenceModel();
|
||||
model.setMembre(membreModel);
|
||||
model.setClub_id((membreModel.getClub() == null) ? null : membreModel.getClub().getId());
|
||||
model.setSaison(form.getSaison());
|
||||
model.setCertificate(form.getCertificate());
|
||||
model.setValidate(form.isValidate());
|
||||
@ -92,9 +93,10 @@ public class LicenceService {
|
||||
.invoke(Unchecked.consumer(count -> {
|
||||
if (count > 0)
|
||||
throw new DBadRequestException("Licence déjà demandée");
|
||||
})).chain(__ -> combRepository.findById(id).chain(combRepository -> {
|
||||
})).chain(__ -> combRepository.findById(id).chain(membreModel2 -> {
|
||||
LicenceModel model = new LicenceModel();
|
||||
model.setMembre(combRepository);
|
||||
model.setClub_id((membreModel2.getClub() == null) ? null : membreModel2.getClub().getId());
|
||||
model.setMembre(membreModel2);
|
||||
model.setSaison(Utils.getSaison());
|
||||
model.setCertificate(form.getCertificate());
|
||||
model.setValidate(false);
|
||||
@ -112,6 +114,10 @@ public class LicenceService {
|
||||
public Uni<?> deleteAskLicence(long id, Consumer<MembreModel> checkPerm) {
|
||||
return repository.findById(id)
|
||||
.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)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LogModel;
|
||||
import fr.titionfire.ffsaf.data.model.LogModel.ActionType;
|
||||
import fr.titionfire.ffsaf.data.model.LogModel.ObjectType;
|
||||
import fr.titionfire.ffsaf.data.model.LoggableModel;
|
||||
import fr.titionfire.ffsaf.data.repository.LogRepository;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@WithSession
|
||||
@RequestScoped
|
||||
public class LoggerService {
|
||||
|
||||
@Inject
|
||||
LogRepository repository;
|
||||
|
||||
@Inject
|
||||
SecurityCtx securityCtx;
|
||||
|
||||
private final List<LogModel> buffer = new ArrayList<>();
|
||||
|
||||
public Uni<?> logA(ActionType action, ObjectType object, String message, String target_name, Long target_id) {
|
||||
return Panache.withTransaction(() -> repository.persist(
|
||||
new LogModel(null, securityCtx.getSubject(), new Date(), action, object, target_id, target_name,
|
||||
message)));
|
||||
}
|
||||
|
||||
public Uni<?> logA(ActionType action, String message, LoggableModel model) {
|
||||
return logA(action, model.getObjectType(), message, model.getObjectName(), model.getId());
|
||||
}
|
||||
|
||||
public Uni<?> logAAdd(LoggableModel model) {
|
||||
return logA(ActionType.ADD, "", model);
|
||||
}
|
||||
|
||||
public Uni<?> logAUpdate(String message, LoggableModel model) {
|
||||
return logA(ActionType.UPDATE, message, model);
|
||||
}
|
||||
|
||||
public Uni<?> logAChange(String champ, Object o1, Object o2, LoggableModel model) {
|
||||
if (Objects.equals(o1, o2))
|
||||
return Uni.createFrom().nullItem();
|
||||
return logA(ActionType.UPDATE, champ + ": " + o1.toString() + " -> " + o2.toString(), model);
|
||||
}
|
||||
|
||||
public Uni<?> logADelete(LoggableModel model) {
|
||||
return logA(ActionType.REMOVE, "", model);
|
||||
}
|
||||
|
||||
public Uni<?> append() {
|
||||
return Panache.withTransaction(() -> repository.persist(buffer))
|
||||
.invoke(__ -> buffer.clear());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
public void log(ActionType action, ObjectType object, String message, String target_name, Long target_id) {
|
||||
buffer.add(new LogModel(null, securityCtx.getSubject(), new Date(), action, object, target_id, target_name,
|
||||
message));
|
||||
}
|
||||
|
||||
public void log(ActionType action, String message, LoggableModel model) {
|
||||
log(action, model.getObjectType(), message, model.getObjectName(), model.getId());
|
||||
}
|
||||
|
||||
public void logAdd(LoggableModel model) {
|
||||
log(ActionType.ADD, "", model);
|
||||
}
|
||||
|
||||
public void logUpdate(String message, LoggableModel model) {
|
||||
log(ActionType.UPDATE, message, model);
|
||||
}
|
||||
|
||||
public void logChange(String champ, Object o1, Object o2, LoggableModel model) {
|
||||
if (Objects.equals(o1, o2))
|
||||
return;
|
||||
log(ActionType.UPDATE,
|
||||
champ + ": " + (o1 == null ? "null" : o1.toString()) + " -> " + (o2 == null ? "null" : o2.toString()),
|
||||
model);
|
||||
}
|
||||
|
||||
public void logDelete(LoggableModel model) {
|
||||
log(ActionType.REMOVE, "", model);
|
||||
}
|
||||
}
|
||||
@ -10,10 +10,10 @@ import fr.titionfire.ffsaf.net2.request.SReqComb;
|
||||
import fr.titionfire.ffsaf.rest.data.MeData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleLicence;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembreInOutData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||
import fr.titionfire.ffsaf.rest.from.ClubMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
@ -37,6 +37,7 @@ import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
||||
@WithSession
|
||||
@ -67,6 +68,9 @@ public class MembreService {
|
||||
@Inject
|
||||
RegisterRepository registerRepository;
|
||||
|
||||
@Inject
|
||||
LoggerService ls;
|
||||
|
||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
repository.find(
|
||||
@ -92,10 +96,17 @@ public class MembreService {
|
||||
if (club == null || club.isBlank()) {
|
||||
query = repository.find(FIND_NAME_REQUEST, Sort.ascending("fname", "lname"), search)
|
||||
.page(Page.ofSize(limit));
|
||||
} else
|
||||
query = repository.find(
|
||||
"LOWER(club.name) LIKE LOWER(?2) AND (" + FIND_NAME_REQUEST + ")",
|
||||
Sort.ascending("fname", "lname"), search, club + "%").page(Page.ofSize(limit));
|
||||
} else {
|
||||
if (club.equals("null")) {
|
||||
query = repository.find(
|
||||
"club IS NULL AND (" + FIND_NAME_REQUEST + ")",
|
||||
Sort.ascending("fname", "lname"), search).page(Page.ofSize(limit));
|
||||
} else {
|
||||
query = repository.find(
|
||||
"LOWER(club.name) LIKE LOWER(?2) AND (" + FIND_NAME_REQUEST + ")",
|
||||
Sort.ascending("fname", "lname"), search, club + "%").page(Page.ofSize(limit));
|
||||
}
|
||||
}
|
||||
return getPageResult(query, limit, page);
|
||||
}
|
||||
|
||||
@ -108,8 +119,8 @@ public class MembreService {
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.chain(membreModel -> {
|
||||
PanacheQuery<MembreModel> query = repository.find(
|
||||
"club = ?1 AND (" + FIND_NAME_REQUEST + ")",
|
||||
Sort.ascending("fname", "lname"), membreModel.getClub(), finalSearch)
|
||||
"club = ?2 AND (" + FIND_NAME_REQUEST + ")",
|
||||
Sort.ascending("fname", "lname"), finalSearch, membreModel.getClub())
|
||||
.page(Page.ofSize(limit));
|
||||
return getPageResult(query, limit, page);
|
||||
});
|
||||
@ -130,6 +141,110 @@ public class MembreService {
|
||||
.invoke(result::setResult));
|
||||
}
|
||||
|
||||
public Uni<List<SimpleMembreInOutData>> getAllExport(String subject) {
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.chain(membreModel -> repository.list("club = ?1", membreModel.getClub()))
|
||||
.chain(membres -> licenceRepository.list("saison = ?1 AND membre IN ?2", Utils.getSaison(), membres)
|
||||
.map(l -> membres.stream().map(m -> SimpleMembreInOutData.fromModel(m, l)).toList()));
|
||||
}
|
||||
|
||||
public Uni<String> allImporte(String subject, List<SimpleMembreInOutData> data) {
|
||||
if (data == null)
|
||||
return Uni.createFrom().nullItem();
|
||||
final List<SimpleMembreInOutData> data2 = data.stream()
|
||||
.filter(dataIn -> dataIn.getNom() != null && !dataIn.getNom()
|
||||
.isBlank() && dataIn.getPrenom() != null && !dataIn.getPrenom().isBlank()).toList();
|
||||
if (data2.isEmpty())
|
||||
return Uni.createFrom().nullItem();
|
||||
AtomicReference<ClubModel> clubModel = new AtomicReference<>();
|
||||
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.chain(membreModel -> {
|
||||
clubModel.set(membreModel.getClub());
|
||||
if (data2.stream().noneMatch(d -> d.getLicence() != null))
|
||||
return Uni.createFrom().item(new ArrayList<MembreModel>());
|
||||
return repository.list("licence IN ?1 OR LOWER(lname || ' ' || fname) IN ?2",
|
||||
data2.stream().map(SimpleMembreInOutData::getLicence).filter(Objects::nonNull).toList(),
|
||||
data2.stream().map(o -> (o.getNom() + " " + o.getPrenom()).toLowerCase()).toList());
|
||||
})
|
||||
.call(Unchecked.function(membres -> {
|
||||
for (MembreModel membreModel : membres) {
|
||||
if (!Objects.equals(membreModel.getClub(), clubModel.get()))
|
||||
throw new DForbiddenException(
|
||||
"Le membre n°" + membreModel.getLicence() + " n'appartient pas à votre club");
|
||||
}
|
||||
Uni<Void> uniResult = Uni.createFrom().voidItem();
|
||||
for (SimpleMembreInOutData dataIn : data2) {
|
||||
MembreModel model = membres.stream()
|
||||
.filter(m -> Objects.equals(m.getLicence(), dataIn.getLicence()) || m.getLname()
|
||||
.equals(dataIn.getNom()) && m.getFname().equals(dataIn.getPrenom())).findFirst()
|
||||
.orElseGet(() -> {
|
||||
MembreModel mm = new MembreModel();
|
||||
mm.setClub(clubModel.get());
|
||||
mm.setLicences(new ArrayList<>());
|
||||
mm.setCountry("FR");
|
||||
return mm;
|
||||
});
|
||||
|
||||
boolean add = model.getId() == null;
|
||||
|
||||
if ((!add && StringSimilarity.similarity(model.getLname().toUpperCase(),
|
||||
dataIn.getNom().toUpperCase()) > 3) || (!add && StringSimilarity.similarity(
|
||||
model.getFname().toUpperCase(), dataIn.getPrenom().toUpperCase()) > 3)) {
|
||||
throw new DBadRequestException(
|
||||
"Pour enregistrer un nouveau membre, veuillez laisser le champ licence vide.");
|
||||
}
|
||||
|
||||
ls.logChange("Nom", model.getLname(), dataIn.getNom().toUpperCase(), model);
|
||||
ls.logChange("Prénom", model.getFname(),
|
||||
dataIn.getPrenom().toUpperCase().charAt(0) + dataIn.getPrenom().substring(1), model);
|
||||
|
||||
model.setLname(dataIn.getNom().toUpperCase());
|
||||
model.setFname(dataIn.getPrenom().toUpperCase().charAt(0) + dataIn.getPrenom().substring(1));
|
||||
|
||||
|
||||
if (dataIn.getEmail() != null && !dataIn.getEmail().isBlank()) {
|
||||
ls.logChange("Email", model.getEmail(), dataIn.getEmail(), model);
|
||||
model.setEmail(dataIn.getEmail());
|
||||
}
|
||||
model.setGenre(Genre.fromString(dataIn.getGenre()));
|
||||
if (dataIn.getBirthdate() != null) {
|
||||
if (model.getBirth_date() == null || !Objects.equals(model.getBirth_date().getTime(),
|
||||
dataIn.getBirthdate().getTime()))
|
||||
ls.logChange("Date de naissance", model.getBirth_date(), dataIn.getBirthdate(), model);
|
||||
model.setBirth_date(dataIn.getBirthdate());
|
||||
model.setCategorie(Utils.getCategoryFormBirthDate(model.getBirth_date(), new Date()));
|
||||
}
|
||||
|
||||
uniResult = uniResult
|
||||
.call(() -> Panache.withTransaction(() -> repository.persist(model)
|
||||
.chain(membreModel1 -> dataIn.isLicenceCurrent() ? licenceRepository.find(
|
||||
"membre.id = ?1 AND saison = ?2", membreModel1.getId(),
|
||||
Utils.getSaison())
|
||||
.firstResult()
|
||||
.call(l -> {
|
||||
if (l == null) {
|
||||
l = new LicenceModel();
|
||||
l.setMembre(membreModel1);
|
||||
l.setClub_id(clubModel.get().getId());
|
||||
l.setValidate(false);
|
||||
l.setSaison(Utils.getSaison());
|
||||
}
|
||||
l.setCertificate(dataIn.getCertif());
|
||||
return licenceRepository.persist(l);
|
||||
}) : licenceRepository.delete(
|
||||
"membre = ?1 AND saison = ?2 AND validate = false", membreModel1,
|
||||
Utils.getSaison()))));
|
||||
if (add)
|
||||
uniResult = uniResult.call(() -> ls.logAAdd(model));
|
||||
else
|
||||
uniResult = uniResult.call(() -> ls.append());
|
||||
}
|
||||
return uniResult;
|
||||
}))
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
|
||||
public Uni<MembreModel> getById(long id) {
|
||||
return repository.findById(id);
|
||||
}
|
||||
@ -148,26 +263,69 @@ public class MembreService {
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, FullMemberForm membre) {
|
||||
return repository.findById(id)
|
||||
return update(repository.findById(id)
|
||||
.chain(membreModel -> clubRepository.findById(membre.getClub())
|
||||
.map(club -> new Pair<>(membreModel, club)))
|
||||
.onItem().transformToUni(pair -> {
|
||||
.onItem().transform(pair -> {
|
||||
MembreModel m = pair.getKey();
|
||||
m.setFname(membre.getFname());
|
||||
m.setLname(membre.getLname().toUpperCase());
|
||||
m.setClub(pair.getValue());
|
||||
m.setCountry(membre.getCountry());
|
||||
m.setBirth_date(membre.getBirth_date());
|
||||
m.setGenre(membre.getGenre());
|
||||
m.setCategorie(membre.getCategorie());
|
||||
|
||||
ls.logChange("Rôle", m.getRole(), membre.getRole(), m);
|
||||
m.setRole(membre.getRole());
|
||||
ls.logChange("Club", m.getClub(), pair.getValue(), m);
|
||||
m.setClub(pair.getValue());
|
||||
ls.logChange("Grade d'arbitrage", m.getGrade_arbitrage(), membre.getGrade_arbitrage(), m);
|
||||
m.setGrade_arbitrage(membre.getGrade_arbitrage());
|
||||
m.setEmail(membre.getEmail());
|
||||
return Panache.withTransaction(() -> repository.persist(m));
|
||||
return m;
|
||||
}), membre, true);
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, FullMemberForm membre, SecurityCtx securityCtx) {
|
||||
return update(repository.findById(id)
|
||||
.invoke(Unchecked.consumer(membreModel -> {
|
||||
if (!securityCtx.isInClubGroup(membreModel.getClub().getId()))
|
||||
throw new DForbiddenException();
|
||||
}))
|
||||
.invoke(Unchecked.consumer(membreModel -> {
|
||||
RoleAsso source = RoleAsso.MEMBRE;
|
||||
if (securityCtx.roleHas("club_president")) source = RoleAsso.PRESIDENT;
|
||||
else if (securityCtx.roleHas("club_secretaire")) source = RoleAsso.SECRETAIRE;
|
||||
else if (securityCtx.roleHas("club_respo_intra")) source = RoleAsso.MEMBREBUREAU;
|
||||
if (!membre.getRole().equals(membreModel.getRole()) && membre.getRole().level >= source.level)
|
||||
throw new DForbiddenException("Permission insuffisante");
|
||||
}))
|
||||
.onItem().transform(target -> {
|
||||
if (!securityCtx.getSubject().equals(target.getUserId())) {
|
||||
ls.logChange("Rôle", target.getRole(), membre.getRole(), target);
|
||||
target.setRole(membre.getRole());
|
||||
}
|
||||
return target;
|
||||
}), membre, false);
|
||||
}
|
||||
|
||||
private Uni<String> update(Uni<MembreModel> uni, FullMemberForm membre, boolean admin) {
|
||||
return uni.chain(target -> {
|
||||
ls.logChange("Prénom", target.getFname(), membre.getFname(), target);
|
||||
target.setFname(membre.getFname());
|
||||
ls.logChange("Nom", target.getLname(), membre.getLname(), target);
|
||||
target.setLname(membre.getLname().toUpperCase());
|
||||
ls.logChange("Pays", target.getCountry(), membre.getCountry(), target);
|
||||
target.setCountry(membre.getCountry());
|
||||
if (membre.getBirth_date() != null && (target.getBirth_date() == null || !Objects.equals(
|
||||
target.getBirth_date().getTime(), membre.getBirth_date().getTime()))) {
|
||||
ls.logChange("Date de naissance", target.getBirth_date(), membre.getBirth_date(), target);
|
||||
target.setBirth_date(membre.getBirth_date());
|
||||
target.setCategorie(Utils.getCategoryFormBirthDate(membre.getBirth_date(), new Date()));
|
||||
}
|
||||
ls.logChange("Genre", target.getGenre(), membre.getGenre(), target);
|
||||
target.setGenre(membre.getGenre());
|
||||
ls.logChange("Email", target.getEmail(), membre.getEmail(), target);
|
||||
target.setEmail(membre.getEmail());
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(target)).call(() -> ls.append());
|
||||
})
|
||||
.invoke(membreModel -> SReqComb.sendIfNeed(serverCustom.clients,
|
||||
SimpleCombModel.fromModel(membreModel)))
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
.call(membreModel -> (admin && membreModel.getUserId() != null) ?
|
||||
((membreModel.getClub() != null) ?
|
||||
keycloakService.setClubGroupMembre(membreModel, membreModel.getClub()) :
|
||||
keycloakService.clearUser(membreModel.getUserId()))
|
||||
@ -184,7 +342,7 @@ public class MembreService {
|
||||
Date dateLimit = calendar.getTime();
|
||||
|
||||
return competitionRepository.list("date > ?1", dateLimit)
|
||||
.call(l ->
|
||||
.call(l -> l.isEmpty() ? Uni.createFrom().nullItem() :
|
||||
Uni.join().all(l.stream().map(competitionModel ->
|
||||
registerRepository.update(
|
||||
"categorie = ?1, club = ?2 where competition = ?3 AND membre = ?4",
|
||||
@ -192,45 +350,14 @@ public class MembreService {
|
||||
membreModel)
|
||||
).toList()).andFailFast());
|
||||
})
|
||||
.call(membreModel -> licenceRepository.update("club_id = ?1 where membre = ?2 AND saison = ?3",
|
||||
(membreModel.getClub() == null) ? null : membreModel.getClub().getId(), membreModel,
|
||||
Utils.getSaison()))
|
||||
.call(membreModel -> membre.getPhoto_data().length > 0 ? ls.logAUpdate("Photo",
|
||||
membreModel) : Uni.createFrom().nullItem())
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, ClubMemberForm membre, SecurityCtx securityCtx) {
|
||||
return repository.findById(id)
|
||||
.invoke(Unchecked.consumer(membreModel -> {
|
||||
if (!securityCtx.isInClubGroup(membreModel.getClub().getId()))
|
||||
throw new DForbiddenException();
|
||||
}))
|
||||
.invoke(Unchecked.consumer(membreModel -> {
|
||||
RoleAsso source = RoleAsso.MEMBRE;
|
||||
if (securityCtx.roleHas("club_president")) source = RoleAsso.PRESIDENT;
|
||||
else if (securityCtx.roleHas("club_secretaire")) source = RoleAsso.SECRETAIRE;
|
||||
else if (securityCtx.roleHas("club_respo_intra")) source = RoleAsso.MEMBREBUREAU;
|
||||
if (!membre.getRole().equals(membreModel.getRole()) && membre.getRole().level >= source.level)
|
||||
throw new DForbiddenException("Permission insuffisante");
|
||||
}))
|
||||
.onItem().transformToUni(target -> {
|
||||
target.setFname(membre.getFname());
|
||||
target.setLname(membre.getLname().toUpperCase());
|
||||
target.setCountry(membre.getCountry());
|
||||
target.setBirth_date(membre.getBirth_date());
|
||||
target.setGenre(membre.getGenre());
|
||||
target.setCategorie(membre.getCategorie());
|
||||
target.setEmail(membre.getEmail());
|
||||
if (!securityCtx.getSubject().equals(target.getUserId()))
|
||||
target.setRole(membre.getRole());
|
||||
return Panache.withTransaction(() -> repository.persist(target));
|
||||
})
|
||||
.invoke(membreModel -> SReqComb.sendIfNeed(serverCustom.clients,
|
||||
SimpleCombModel.fromModel(membreModel)))
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
keycloakService.setAutoRoleMembre(membreModel.getUserId(), membreModel.getRole(),
|
||||
membreModel.getGrade_arbitrage()) : Uni.createFrom().nullItem())
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
keycloakService.setEmail(membreModel.getUserId(), membreModel.getEmail()) : Uni.createFrom()
|
||||
.nullItem())
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
|
||||
public Uni<Long> add(FullMemberForm input) {
|
||||
return clubRepository.findById(input.getClub())
|
||||
@ -238,6 +365,7 @@ public class MembreService {
|
||||
MembreModel model = getMembreModel(input, clubModel);
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
})
|
||||
.call(membreModel -> ls.logAAdd(membreModel))
|
||||
.invoke(membreModel -> SReqComb.sendIfNeedAdd(serverCustom.clients,
|
||||
SimpleCombModel.fromModel(membreModel)))
|
||||
.map(MembreModel::getId);
|
||||
@ -251,6 +379,7 @@ public class MembreService {
|
||||
model.setGrade_arbitrage(GradeArbitrage.NA);
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
})
|
||||
.call(membreModel -> ls.logAAdd(membreModel))
|
||||
.invoke(membreModel -> SReqComb.sendIfNeedAdd(serverCustom.clients,
|
||||
SimpleCombModel.fromModel(membreModel)))
|
||||
.map(MembreModel::getId);
|
||||
@ -260,6 +389,7 @@ public class MembreService {
|
||||
return repository.findById(id)
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
keycloakService.removeAccount(membreModel.getUserId()) : Uni.createFrom().nullItem())
|
||||
.call(membreModel -> ls.logADelete(membreModel))
|
||||
.call(membreModel -> Panache.withTransaction(() -> repository.delete(membreModel)))
|
||||
.invoke(membreModel -> SReqComb.sendRm(serverCustom.clients, id))
|
||||
.map(__ -> "Ok");
|
||||
@ -271,6 +401,12 @@ public class MembreService {
|
||||
if (!securityCtx.isInClubGroup(membreModel.getClub().getId()))
|
||||
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()
|
||||
.invoke(Unchecked.consumer(l -> {
|
||||
if (l > 0)
|
||||
@ -278,6 +414,7 @@ public class MembreService {
|
||||
})))
|
||||
.call(membreModel -> (membreModel.getUserId() != null) ?
|
||||
keycloakService.removeAccount(membreModel.getUserId()) : Uni.createFrom().nullItem())
|
||||
.call(membreModel -> ls.logADelete(membreModel))
|
||||
.call(membreModel -> Panache.withTransaction(() -> repository.delete(membreModel)))
|
||||
.invoke(membreModel -> SReqComb.sendRm(serverCustom.clients, id))
|
||||
.call(__ -> Utils.deleteMedia(id, media, "ppMembre"))
|
||||
@ -286,8 +423,10 @@ public class MembreService {
|
||||
|
||||
public Uni<?> setUserId(Long id, String id1) {
|
||||
return repository.findById(id).chain(membreModel -> {
|
||||
ls.logChange("KC UUID", membreModel.getUserId(), id1, membreModel);
|
||||
membreModel.setUserId(id1);
|
||||
return Panache.withTransaction(() -> repository.persist(membreModel));
|
||||
return Panache.withTransaction(() -> repository.persist(membreModel))
|
||||
.call(() -> ls.append());
|
||||
});
|
||||
}
|
||||
|
||||
@ -300,7 +439,7 @@ public class MembreService {
|
||||
model.setGenre(input.getGenre());
|
||||
model.setCountry(input.getCountry());
|
||||
model.setBirth_date(input.getBirth_date());
|
||||
model.setCategorie(input.getCategorie());
|
||||
model.setCategorie(Utils.getCategoryFormBirthDate(input.getBirth_date(), new Date()));
|
||||
model.setClub(clubModel);
|
||||
model.setRole(input.getRole());
|
||||
model.setGrade_arbitrage(input.getGrade_arbitrage());
|
||||
|
||||
@ -102,12 +102,12 @@ public class AffiliationRequestEndpoints {
|
||||
@APIResponse(responseCode = "404", description = "Demande d'affiliation non trouvée")
|
||||
})
|
||||
public Uni<?> getDelAffRequest(
|
||||
@Parameter(description = "L'identifiant de la demande d'affiliation") @PathParam("id") long id) {
|
||||
@Parameter(description = "L'identifiant de la demande d'affiliation") @PathParam("id") long id, @QueryParam("reason") String reason) {
|
||||
return service.getRequest(id).invoke(Unchecked.consumer(o -> {
|
||||
if (o.getClub() == null && !securityCtx.roleHas("federation_admin"))
|
||||
throw new DForbiddenException();
|
||||
})).invoke(o -> checkPerm.accept(o.getClub()))
|
||||
.chain(o -> service.deleteReqAffiliation(id));
|
||||
.chain(o -> service.deleteReqAffiliation(id, reason));
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
||||
@ -145,7 +145,7 @@ public class ClubEndpoints {
|
||||
)).invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK"))
|
||||
throw new DInternalError("Impossible de reconnaitre le fichier: " + out);
|
||||
}));
|
||||
})); // TODO log
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
}).chain(() -> {
|
||||
@ -154,7 +154,7 @@ public class ClubEndpoints {
|
||||
)).invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK"))
|
||||
throw new DInternalError("Impossible de reconnaitre le fichier: " + out);
|
||||
}));
|
||||
})); // TODO log
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
@ -178,13 +178,13 @@ public class ClubEndpoints {
|
||||
})).call(id -> {
|
||||
if (input.getLogo().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getLogo(), media, "ppClub"
|
||||
));
|
||||
)); // TODO log
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
}).call(id -> {
|
||||
if (input.getStatus().length > 0)
|
||||
return Uni.createFrom().future(Utils.replacePhoto(id, input.getStatus(), media, "clubStatus"
|
||||
));
|
||||
)); // TODO log
|
||||
else
|
||||
return Uni.createFrom().nullItem();
|
||||
});
|
||||
|
||||
@ -2,8 +2,8 @@ package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.MembreService;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembreInOutData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DInternalError;
|
||||
import fr.titionfire.ffsaf.rest.from.ClubMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.utils.PageResult;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
@ -21,6 +21,8 @@ import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
|
||||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
|
||||
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "Membre club", description = "Gestion des membres (pour les clubs)")
|
||||
@RolesAllowed({"club_president", "club_secretaire", "club_respo_intra"})
|
||||
@Path("api/member")
|
||||
@ -55,6 +57,34 @@ public class MembreClubEndpoints {
|
||||
return membreService.search(limit, page - 1, search, securityCtx.getSubject());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("club/export")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(summary = "Exporte les membres du club", description = "Exporte les membres du club")
|
||||
@APIResponses(value = {
|
||||
@APIResponse(responseCode = "200", description = "Les membres du club ont été exportés avec succès"),
|
||||
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
||||
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
||||
})
|
||||
public Uni<List<SimpleMembreInOutData>> exportMembre() {
|
||||
return membreService.getAllExport(securityCtx.getSubject());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("club/import")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(summary = "Importer les membres du club", description = "Importer tout ou en partie les membres du club")
|
||||
@APIResponses(value = {
|
||||
@APIResponse(responseCode = "200", description = "Les membres du club ont été importés avec succès"),
|
||||
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
||||
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
||||
})
|
||||
public Uni<?> importMembre(List<SimpleMembreInOutData> dataIn) {
|
||||
System.out.println("importMembre");
|
||||
return membreService.allImporte(securityCtx.getSubject(), dataIn);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("club/{id}")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@ -68,7 +98,7 @@ public class MembreClubEndpoints {
|
||||
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
||||
})
|
||||
public Uni<String> setMembre(
|
||||
@Parameter(description = "Identifiant de membre") @PathParam("id") long id, ClubMemberForm input) {
|
||||
@Parameter(description = "Identifiant de membre") @PathParam("id") long id, FullMemberForm input) {
|
||||
return membreService.update(id, input, securityCtx)
|
||||
.invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to update data: " + out);
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@RegisterForReflection
|
||||
@AllArgsConstructor
|
||||
public class SimpleMembreInOutData {
|
||||
Integer licence;
|
||||
String nom;
|
||||
String prenom;
|
||||
String email;
|
||||
String genre;
|
||||
Date birthdate;
|
||||
boolean licenceCurrent;
|
||||
String certif;
|
||||
|
||||
public static SimpleMembreInOutData fromModel(MembreModel membreModel, List<LicenceModel> lc) {
|
||||
LicenceModel currentLicence = lc.stream().filter(l -> l.getMembre().getId().equals(membreModel.getId()))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
return new SimpleMembreInOutData(
|
||||
membreModel.getLicence(),
|
||||
membreModel.getLname(),
|
||||
membreModel.getFname(),
|
||||
membreModel.getEmail(),
|
||||
membreModel.getGenre().str,
|
||||
membreModel.getBirth_date(),
|
||||
currentLicence != null,
|
||||
currentLicence == null ? null : currentLicence.getCertificate()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import lombok.Getter;
|
||||
import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
||||
import org.jboss.resteasy.reactive.PartType;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
public class ClubMemberForm {
|
||||
@Schema(description = "L'identifiant du membre.", example = "1234567", required = true)
|
||||
@FormParam("id")
|
||||
private String id = null;
|
||||
|
||||
@Schema(description = "Le nom du membre.", example = "Dupont", required = true)
|
||||
@FormParam("lname")
|
||||
private String lname = null;
|
||||
|
||||
@Schema(description = "Le prénom du membre.", example = "Jean", required = true)
|
||||
@FormParam("fname")
|
||||
private String fname = null;
|
||||
|
||||
@Schema(description = "La catégorie du membre.", example = "SENIOR", required = true)
|
||||
@FormParam("categorie")
|
||||
private Categorie categorie = null;
|
||||
|
||||
@Schema(description = "Le genre du membre.", example = "H", required = true)
|
||||
@FormParam("genre")
|
||||
private Genre genre;
|
||||
|
||||
@Schema(description = "Le pays du membre.", example = "FR", required = true)
|
||||
@FormParam("country")
|
||||
private String country;
|
||||
|
||||
@Schema(description = "La date de naissance du membre.", required = true)
|
||||
@FormParam("birth_date")
|
||||
private Date birth_date;
|
||||
|
||||
@Schema(description = "L'adresse e-mail du membre.", example = "jean.dupont@example.com", required = true)
|
||||
@FormParam("email")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "Le rôle du membre dans l'association.", example = "MEMBRE", required = true)
|
||||
@FormParam("role")
|
||||
private RoleAsso role;
|
||||
|
||||
@Schema(description = "La photo du membre.")
|
||||
@FormParam("photo_data")
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
private byte[] photo_data = new byte[0];
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ClubMemberForm{" +
|
||||
"id='" + id + '\'' +
|
||||
", lname='" + lname + '\'' +
|
||||
", fname='" + fname + '\'' +
|
||||
", categorie=" + categorie +
|
||||
", genre=" + genre +
|
||||
", country='" + country + '\'' +
|
||||
", birth_date=" + birth_date +
|
||||
", email='" + email + '\'' +
|
||||
", role=" + role +
|
||||
", url_photo=" + photo_data.length +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
@ -26,10 +25,6 @@ public class FullMemberForm {
|
||||
@FormParam("fname")
|
||||
private String fname = null;
|
||||
|
||||
@Schema(description = "La catégorie du membre.", example = "SENIOR")
|
||||
@FormParam("categorie")
|
||||
private Categorie categorie = null;
|
||||
|
||||
@Schema(description = "L'identifiant du club du membre.", example = "1")
|
||||
@FormParam("club")
|
||||
private Long club = null;
|
||||
@ -38,10 +33,6 @@ public class FullMemberForm {
|
||||
@FormParam("genre")
|
||||
private Genre genre;
|
||||
|
||||
@Schema(description = "Le numéro de licence du membre.", example = "12345")
|
||||
@FormParam("licence")
|
||||
private int licence;
|
||||
|
||||
@Schema(description = "Le pays du membre.", example = "FR")
|
||||
@FormParam("country")
|
||||
private String country;
|
||||
@ -60,7 +51,7 @@ public class FullMemberForm {
|
||||
|
||||
@Schema(description = "Le grade d'arbitrage du membre.", example = "ASSESSEUR")
|
||||
@FormParam("grade_arbitrage")
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
private GradeArbitrage grade_arbitrage = GradeArbitrage.NA;
|
||||
|
||||
@Schema(description = "La photo du membre.")
|
||||
@FormParam("photo_data")
|
||||
@ -73,11 +64,8 @@ public class FullMemberForm {
|
||||
"id='" + id + '\'' +
|
||||
", lname='" + lname + '\'' +
|
||||
", fname='" + fname + '\'' +
|
||||
", categorie=" + categorie +
|
||||
", club=" + club +
|
||||
", genre=" + genre +
|
||||
", licence=" + licence +
|
||||
", country='" + country + '\'' +
|
||||
", birth_date=" + birth_date +
|
||||
", email='" + email + '\'' +
|
||||
", role=" + role +
|
||||
|
||||
@ -14,6 +14,19 @@ public enum Genre {
|
||||
this.str = name;
|
||||
}
|
||||
|
||||
public static Genre fromString(String genre) {
|
||||
if (genre == null) {
|
||||
return NA;
|
||||
}
|
||||
if (genre.equalsIgnoreCase("Homme") || genre.equalsIgnoreCase("H")) {
|
||||
return H;
|
||||
} else if (genre.equalsIgnoreCase("Femme") || genre.equalsIgnoreCase("F")) {
|
||||
return F;
|
||||
} else {
|
||||
return NA;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return str;
|
||||
|
||||
@ -38,6 +38,8 @@ database.port=3306
|
||||
database.user=root
|
||||
database.pass=
|
||||
|
||||
notif.affRequest.mail=
|
||||
|
||||
siren-api.key=siren-ap
|
||||
quarkus.rest-client."fr.titionfire.ffsaf.rest.client.SirenService".url=https://data.siren-api.fr/
|
||||
|
||||
|
||||
185
src/main/webapp/package-lock.json
generated
185
src/main/webapp/package-lock.json
generated
@ -24,7 +24,9 @@
|
||||
"react-loader-spinner": "^6.1.6",
|
||||
"react-router-dom": "^6.21.2",
|
||||
"react-toastify": "^10.0.4",
|
||||
"recharts": "^2.15.1"
|
||||
"recharts": "^2.15.1",
|
||||
"xlsx": "^0.18.5",
|
||||
"xlsx-js-style": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.43",
|
||||
@ -1410,6 +1412,14 @@
|
||||
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/adler-32": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz",
|
||||
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "6.12.6",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
||||
@ -1698,6 +1708,18 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/cfb": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz",
|
||||
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
|
||||
"dependencies": {
|
||||
"adler-32": "~1.3.0",
|
||||
"crc-32": "~1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
||||
@ -1720,6 +1742,14 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/codepage": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz",
|
||||
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/color-convert": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
|
||||
@ -1746,6 +1776,11 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "2.17.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz",
|
||||
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg=="
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@ -1758,6 +1793,17 @@
|
||||
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/crc-32": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
|
||||
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
|
||||
"bin": {
|
||||
"crc32": "bin/crc32.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
@ -2477,6 +2523,14 @@
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
|
||||
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
|
||||
},
|
||||
"node_modules/exit-on-epipe": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz",
|
||||
"integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
@ -2512,6 +2566,11 @@
|
||||
"reusify": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/fflate": {
|
||||
"version": "0.3.11",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.3.11.tgz",
|
||||
"integrity": "sha512-Rr5QlUeGN1mbOHlaqcSYMKVpPbgLy0AWT/W0EHxA6NGI12yO1jpoui2zBBvU2G824ltM6Ut8BFgfHSBGfkmS0A=="
|
||||
},
|
||||
"node_modules/file-entry-cache": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
|
||||
@ -2601,6 +2660,14 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/frac": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz",
|
||||
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
@ -3725,6 +3792,17 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/printj": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/printj/-/printj-1.1.2.tgz",
|
||||
"integrity": "sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==",
|
||||
"bin": {
|
||||
"printj": "bin/printj.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/proj4": {
|
||||
"version": "2.11.0",
|
||||
"resolved": "https://registry.npmjs.org/proj4/-/proj4-2.11.0.tgz",
|
||||
@ -4237,6 +4315,17 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ssf": {
|
||||
"version": "0.11.2",
|
||||
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz",
|
||||
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
|
||||
"dependencies": {
|
||||
"frac": "~1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/string.prototype.matchall": {
|
||||
"version": "4.0.10",
|
||||
"resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.10.tgz",
|
||||
@ -4759,12 +4848,106 @@
|
||||
"resolved": "https://registry.npmjs.org/wkt-parser/-/wkt-parser-1.3.3.tgz",
|
||||
"integrity": "sha512-ZnV3yH8/k58ZPACOXeiHaMuXIiaTk1t0hSUVisbO0t4RjA5wPpUytcxeyiN2h+LZRrmuHIh/1UlrR9e7DHDvTw=="
|
||||
},
|
||||
"node_modules/wmf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz",
|
||||
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/word": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz",
|
||||
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==",
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/xlsx": {
|
||||
"version": "0.18.5",
|
||||
"resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz",
|
||||
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
|
||||
"dependencies": {
|
||||
"adler-32": "~1.3.0",
|
||||
"cfb": "~1.2.1",
|
||||
"codepage": "~1.15.0",
|
||||
"crc-32": "~1.2.1",
|
||||
"ssf": "~0.11.2",
|
||||
"wmf": "~1.0.1",
|
||||
"word": "~0.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"xlsx": "bin/xlsx.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/xlsx-js-style": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/xlsx-js-style/-/xlsx-js-style-1.2.0.tgz",
|
||||
"integrity": "sha512-DDT4FXFSWfT4DXMSok/m3TvmP1gvO3dn0Eu/c+eXHW5Kzmp7IczNkxg/iEPnImbG9X0Vb8QhROda5eatSR/97Q==",
|
||||
"dependencies": {
|
||||
"adler-32": "~1.2.0",
|
||||
"cfb": "^1.1.4",
|
||||
"codepage": "~1.14.0",
|
||||
"commander": "~2.17.1",
|
||||
"crc-32": "~1.2.0",
|
||||
"exit-on-epipe": "~1.0.1",
|
||||
"fflate": "^0.3.8",
|
||||
"ssf": "~0.11.2",
|
||||
"wmf": "~1.0.1",
|
||||
"word": "~0.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"xlsx": "bin/xlsx.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/xlsx-js-style/node_modules/adler-32": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.2.0.tgz",
|
||||
"integrity": "sha512-/vUqU/UY4MVeFsg+SsK6c+/05RZXIHZMGJA+PX5JyWI0ZRcBpupnRuPLU/NXXoFwMYCPCoxIfElM2eS+DUXCqQ==",
|
||||
"dependencies": {
|
||||
"exit-on-epipe": "~1.0.1",
|
||||
"printj": "~1.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"adler32": "bin/adler32.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/xlsx-js-style/node_modules/codepage": {
|
||||
"version": "1.14.0",
|
||||
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.14.0.tgz",
|
||||
"integrity": "sha512-iz3zJLhlrg37/gYRWgEPkaFTtzmnEv1h+r7NgZum2lFElYQPi0/5bnmuDfODHxfp0INEfnRqyfyeIJDbb7ahRw==",
|
||||
"dependencies": {
|
||||
"commander": "~2.14.1",
|
||||
"exit-on-epipe": "~1.0.1"
|
||||
},
|
||||
"bin": {
|
||||
"codepage": "bin/codepage.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/xlsx-js-style/node_modules/codepage/node_modules/commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw=="
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||
|
||||
@ -26,7 +26,9 @@
|
||||
"react-loader-spinner": "^6.1.6",
|
||||
"react-router-dom": "^6.21.2",
|
||||
"react-toastify": "^10.0.4",
|
||||
"recharts": "^2.15.1"
|
||||
"recharts": "^2.15.1",
|
||||
"xlsx": "^0.18.5",
|
||||
"xlsx-js-style": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.43",
|
||||
|
||||
@ -1,12 +1,21 @@
|
||||
import {useEffect, useReducer, useState} from "react";
|
||||
import {SimpleReducer} from "../../utils/SimpleReducer.jsx";
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faAdd, faTrashCan} from "@fortawesome/free-solid-svg-icons";
|
||||
import {faAdd, faCircleQuestion, faTrashCan} from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
export function ContactEditor({data}) {
|
||||
const [state, dispatch] = useReducer(SimpleReducer, [])
|
||||
const [out_data, setOutData] = useState({})
|
||||
|
||||
const tooltipText = {
|
||||
SITE: "Site web du club avec ou sans le 'https://'</br>Exemple: ffsaf.fr</br>Ou https://ffsaf.fr",
|
||||
FACEBOOK: "Page Facebook du club débutant par 'https://www.facebook.com/'</br>Exemple: https://www.facebook.com/ffmsf",
|
||||
TELEPHONE: "Numéro de téléphone du club<br>Exemple: 06 12 13 78 55",
|
||||
INSTAGRAM: "Compte Instagram du club débutant par 'https://www.instagram.com/'</br>Exemple: https://www.instagram.com/ff_msf",
|
||||
COURRIEL: "Adresse e-mail du club<br>Exemple: contact@ffsaf.fr",
|
||||
AUTRE: "Autre contact du club",
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let i = 0;
|
||||
for (const key in data.contact) {
|
||||
@ -22,6 +31,9 @@ export function ContactEditor({data}) {
|
||||
out_data2[d.data.type] = d.data.value
|
||||
})
|
||||
setOutData(out_data2)
|
||||
|
||||
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
|
||||
}, [state]);
|
||||
|
||||
return <div className="row mb-3">
|
||||
@ -49,6 +61,10 @@ export function ContactEditor({data}) {
|
||||
onChange={(e) => {
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: {type: d.data.type, value: e.target.value}}})
|
||||
}}/>
|
||||
<button type="button" className="btn btn-outline-info" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
data-bs-title={tooltipText[d.data.type]} data-bs-html="true">
|
||||
<FontAwesomeIcon icon={faCircleQuestion}/>
|
||||
</button>
|
||||
<button className="btn btn-danger" type="button"
|
||||
onClick={() => dispatch({type: 'REMOVE', payload: d.id})}><FontAwesomeIcon
|
||||
icon={faTrashCan}/>
|
||||
@ -83,4 +99,4 @@ export function ContactEditor({data}) {
|
||||
</div>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,13 +3,13 @@ import {useFetch} from "../hooks/useFetch.js";
|
||||
import {AxiosError} from "../components/AxiosError.jsx";
|
||||
import {ThreeDots} from "react-loader-spinner";
|
||||
import {useEffect, useState} from "react";
|
||||
import {Input} from "../components/Input.jsx";
|
||||
import {useLocation, useNavigate} from "react-router-dom";
|
||||
import {Checkbox} from "../components/MemberCustomFiels.jsx";
|
||||
import axios from "axios";
|
||||
import * as Tools from "../utils/Tools.js";
|
||||
import {apiAxios, errFormater} from "../utils/Tools.js";
|
||||
import {toast} from "react-toastify";
|
||||
import {SearchBar} from "../components/SearchBar.jsx";
|
||||
import * as XLSX from "xlsx-js-style";
|
||||
|
||||
export function MemberList({source}) {
|
||||
const {hash} = useLocation();
|
||||
@ -100,12 +100,228 @@ export function MemberList({source}) {
|
||||
clubFilter={clubFilter} setClubFilter={setClubFilter} source={source}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{source === "club" &&
|
||||
<div className="card mb-4">
|
||||
<div className="card-header">Gestion groupée</div>
|
||||
<div className="card-body">
|
||||
<FileOutput/>
|
||||
<div style={{marginTop: "1.5em"}}></div>
|
||||
<FileInput/>
|
||||
</div>
|
||||
</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
function FileOutput() {
|
||||
function formatColumnDate(worksheet, col) {
|
||||
const range = XLSX.utils.decode_range(worksheet['!ref'])
|
||||
// note: range.s.r + 1 skips the header row
|
||||
for (let row = range.s.r + 1; row <= range.e.r; ++row) {
|
||||
const ref = XLSX.utils.encode_cell({r: row, c: col})
|
||||
if (worksheet[ref] && worksheet[ref].t === "n") {
|
||||
worksheet[ref].v = Math.trunc(worksheet[ref].v)
|
||||
} else {
|
||||
worksheet[ref].t = "n"
|
||||
}
|
||||
worksheet[ref].z = "dd/mm/yyyy"
|
||||
}
|
||||
}
|
||||
|
||||
const handleFileDownload = () => {
|
||||
toast.promise(
|
||||
apiAxios.get(`/member/club/export`),
|
||||
{
|
||||
pending: "Exportation des licences...",
|
||||
success: "Licences exportées",
|
||||
error: {
|
||||
render({data}) {
|
||||
return errFormater(data, "Impossible d'exporté les licences")
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
const dataOut = []
|
||||
for (const e of data.data) {
|
||||
const tmp = {
|
||||
licence: e.licence,
|
||||
nom: e.nom,
|
||||
prenom: e.prenom,
|
||||
email: e.email,
|
||||
genre: e.genre,
|
||||
birthdate: new Date(e.birthdate),
|
||||
licenceCurrent: e.licenceCurrent ? 'X' : '',
|
||||
certif: e.certif ? e.certif.split("¤")[0] : '',
|
||||
certifDate: e.certif ? new Date(e.certif.split("¤")[1]) : '',
|
||||
}
|
||||
|
||||
//tmp.birthdate.setMilliseconds(0);
|
||||
//tmp.birthdate.setSeconds(0);
|
||||
//tmp.birthdate.setMinutes(0);
|
||||
//tmp.birthdate.setHours(0);
|
||||
//
|
||||
//console.log(tmp.birthdate);
|
||||
dataOut.push(tmp)
|
||||
}
|
||||
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.json_to_sheet(dataOut);
|
||||
XLSX.utils.sheet_add_aoa(ws, [["Licence", "Nom", "Prénom", "Email", "Genre", "Date de naissance", "Licence en cours", "Nom médecin certificat", "Date certificat"]], {origin: 'A1'});
|
||||
// XLSX.utils.sheet_add_json(ws, dataOut, {skipHeader: true, origin: 'A2'});
|
||||
|
||||
formatColumnDate(ws, 5)
|
||||
formatColumnDate(ws, 8)
|
||||
console.log(ws)
|
||||
//ws["!data"][0][0].z = "yyyy-mm-dd hh:mm:ss"
|
||||
ws["!cols"] = [{wch: 7}, {wch: 16}, {wch: 16}, {wch: 30}, {wch: 9}, {wch: 12}, {wch: 6}, {wch: 13}, {wch: 12}]
|
||||
|
||||
XLSX.utils.book_append_sheet(wb, ws, `Saison ${Tools.getSaison()}-${Tools.getSaison() + 1}`);
|
||||
XLSX.writeFile(wb, "output.xlsx");
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-primary" onClick={handleFileDownload}>Télécharger l'Excel des membres</button>
|
||||
<small>À utiliser comme template pour mettre à jour les informations</small>
|
||||
</div>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function FileInput() {
|
||||
const re = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
|
||||
|
||||
function excelDateToJSDate(serial) {
|
||||
const utcDays = Math.floor(serial - 25569);
|
||||
const utcValue = utcDays * 86400;
|
||||
return new Date(utcValue * 1000);
|
||||
}
|
||||
|
||||
const handleFileUpload = (e) => {
|
||||
const file = e.target.files[0];
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = (event) => {
|
||||
const workbook = XLSX.read(event.target.result, {type: 'binary'});
|
||||
const sheet = workbook.Sheets[`Saison ${Tools.getSaison()}-${Tools.getSaison() + 1}`];
|
||||
const sheetData = XLSX.utils.sheet_to_json(sheet);
|
||||
|
||||
const dataOut = []
|
||||
let error = 0;
|
||||
let cetifNotFill = 0;
|
||||
for (let i = 0; i < sheetData.length; i++) {
|
||||
const line = sheetData[i];
|
||||
// noinspection NonAsciiCharacters,JSNonASCIINames
|
||||
const tmp = {
|
||||
licence: line["Licence"],
|
||||
nom: line["Nom"],
|
||||
prenom: line["Prénom"],
|
||||
email: line["Email"],
|
||||
genre: line["Genre"],
|
||||
birthdate: line["Date de naissance"],
|
||||
licenceCurrent: line["Licence en cours"] === undefined ? false : line["Licence en cours"].toLowerCase() === "x",
|
||||
certif: "",
|
||||
}
|
||||
|
||||
if (tmp.nom === undefined || tmp.nom === "") {
|
||||
toast.error("Nom vide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
if (tmp.prenom === undefined || tmp.prenom === "") {
|
||||
toast.error("Prénom vide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
|
||||
if (tmp.licenceCurrent) { // need check full data
|
||||
if (tmp.email === undefined || tmp.email === "") {
|
||||
toast.error("Email vide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
if (!re.test(tmp.email)) {
|
||||
toast.error("Email invalide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
// noinspection NonAsciiCharacters,JSNonASCIINames
|
||||
if (line["Nom médecin certificat"] === undefined || line["Nom médecin certificat"] === "" ||
|
||||
line["Date certificat"] === undefined || line["Date certificat"] === "") {
|
||||
cetifNotFill++;
|
||||
} else {
|
||||
try {
|
||||
const date = excelDateToJSDate(line["Date certificat"]);
|
||||
if (Number.isNaN(date.getFullYear())) {
|
||||
toast.error("Format de la date de certificat invalide à la ligne " + (i + 2))
|
||||
error++;
|
||||
} else {
|
||||
// noinspection JSNonASCIINames
|
||||
tmp.certif = line["Nom médecin certificat"] + "¤" + date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error("Format de la date de certificat invalide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp.birthdate === undefined || tmp.birthdate === "") {
|
||||
toast.error("Date de naissance vide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp.birthdate !== undefined && tmp.birthdate !== "") {
|
||||
console.log(tmp.birthdate);
|
||||
try {
|
||||
tmp.birthdate = excelDateToJSDate(tmp.birthdate).toISOString();
|
||||
} catch (e) {
|
||||
toast.error("Format de la date de naissance invalide à la ligne " + (i + 2))
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
dataOut.push(tmp)
|
||||
}
|
||||
|
||||
if (error > 0) {
|
||||
toast.error(`${error} erreur(s) dans le fichier, opération annulée`)
|
||||
} else {
|
||||
console.log(dataOut);
|
||||
|
||||
toast.promise(
|
||||
apiAxios.put(`/member/club/import`, dataOut),
|
||||
{
|
||||
pending: "Envoie des changement en cours",
|
||||
success: "Changement envoyé avec succès 🎉",
|
||||
error: {
|
||||
render({data}) {
|
||||
return errFormater(data, "Échec de l'envoie des changements")
|
||||
}
|
||||
}
|
||||
}
|
||||
).then(_ => {
|
||||
if (cetifNotFill > 0)
|
||||
toast.warn(`${cetifNotFill} certificat(s) médical(aux) non rempli(s)`)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsBinaryString(file);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<span>Charger l'Excel</span>
|
||||
<div className="input-group">
|
||||
<input type="file" className="form-control" id="logo" name="logo" accept=".xls,.xlsx" onChange={handleFileUpload}/>
|
||||
</div>
|
||||
<small>Merci d'utiliser le fichier ci-dessus comme base, ne pas renommer les colonnes ni modifier les n° de licences.</small>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MakeCentralPanel({data, visibleMember, navigate, showLicenceState, page, source}) {
|
||||
const pages = []
|
||||
for (let i = 1; i <= data.page_count; i++) {
|
||||
@ -119,7 +335,8 @@ function MakeCentralPanel({data, visibleMember, navigate, showLicenceState, page
|
||||
<small>Ligne {((page - 1) * data.page_size) + 1} à {
|
||||
(page * data.page_size > data.result_count) ? data.result_count : (page * data.page_size)} (page {page} sur {data.page_count})</small>
|
||||
<div className="list-group">
|
||||
{visibleMember.map(member => (<MakeRow key={member.id} member={member} navigate={navigate} showLicenceState={showLicenceState} source={source}/>))}
|
||||
{visibleMember.map(member => (
|
||||
<MakeRow key={member.id} member={member} navigate={navigate} showLicenceState={showLicenceState} source={source}/>))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
@ -176,18 +393,28 @@ function FiltreBar({showLicenceState, setShowLicenceState, data, clubFilter, set
|
||||
<div className="mb-3">
|
||||
<Checkbox value={showLicenceState} onChange={setShowLicenceState} label="Afficher l'état des licences"/>
|
||||
</div>
|
||||
{source !== "club" &&
|
||||
<div className="mb-3">
|
||||
{source !== "club" && <ClubSelectFilter clubFilter={clubFilter} setClubFilter={setClubFilter}/>}
|
||||
</div>
|
||||
}
|
||||
|
||||
function ClubSelectFilter({clubFilter, setClubFilter}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/club/no_detail`, setLoading, 1)
|
||||
|
||||
return <>
|
||||
{data
|
||||
? <div className="mb-3">
|
||||
<select className="form-select" value={clubFilter} onChange={event => setClubFilter(event.target.value)}>
|
||||
<option value="">--- tout les clubs ---</option>
|
||||
{allClub && allClub.map((value, index) => {
|
||||
return <option key={index} value={value}>{value}</option>
|
||||
})
|
||||
}
|
||||
<option value="null">--- sans club ---</option>
|
||||
{data.map(club => (<option key={club.id} value={club.name}>{club.name}</option>))}
|
||||
</select>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
function Def() {
|
||||
@ -198,4 +425,4 @@ function Def() {
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,9 +38,9 @@ export function AffiliationReqPage() {
|
||||
function Content({data, refresh}) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleRm = (e) => {
|
||||
const handleRm = (reason) => {
|
||||
toast.promise(
|
||||
apiAxios.delete(`/affiliation/request/${data.id}`),
|
||||
apiAxios.delete(`/affiliation/request/${data.id}?reason=${encodeURIComponent(reason)}`),
|
||||
{
|
||||
pending: "Suppression de la demande d'affiliation en cours",
|
||||
success: "Demande d'affiliation supprimée avec succès 🎉",
|
||||
@ -219,8 +219,8 @@ function Content({data, refresh}) {
|
||||
<button type="submit" value="accept" className="btn btn-success">Accepter</button>
|
||||
<button type="submit" value="save" className="btn btn-primary">Enregistrer</button>
|
||||
<button className="btn btn-danger" value="rm" data-bs-toggle="modal" data-bs-target="#confirm-delete">Refuser</button>
|
||||
<ConfirmDialog title="Refuser la demande" message="Êtes-vous sûr de vouloir refuser cette demande ?"
|
||||
onConfirm={handleRm}/>
|
||||
<ConfirmReasonDialog title="Refuser la demande" message="Êtes-vous sûr de vouloir refuser cette demande ?"
|
||||
onConfirm={handleRm}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -228,6 +228,34 @@ function Content({data, refresh}) {
|
||||
</>
|
||||
}
|
||||
|
||||
function ConfirmReasonDialog({onConfirm, id = "confirm-delete"}) {
|
||||
const [reason, setReason] = useState("")
|
||||
return <div className="modal fade" id={id} tabIndex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<h4 className="modal-title" id="myModalLabel">"Refuser la demande"</h4>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div className="row mb-3">
|
||||
<div className="col">
|
||||
<label htmlFor="reason" className="form-label">Raison du refus</label>
|
||||
<textarea className="form-control" id="reason" name="reason" rows="3"
|
||||
placeholder="Veuillez indiquer la raison du refus" value={reason}
|
||||
onChange={e => setReason(e.target.value)}></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<span>Êtes-vous sûr de vouloir refuser cette demande ?</span>
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button type="button" className="btn btn-default" data-dismiss="modal" data-bs-dismiss="modal">Annuler</button>
|
||||
<a className="btn btn-danger btn-ok" data-bs-dismiss="modal" onClick={_ => onConfirm(reason)}>Confirmer</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
function MemberPart({index, member}) {
|
||||
const [mode, setMode] = useState(member.licence >= 0 ? 0 : 2)
|
||||
const [current, setCurrent] = useState(-1)
|
||||
@ -394,4 +422,4 @@ function MemberSimilar({member, current, setCurrent, mode, index, setEmail}) {
|
||||
</button>
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,10 +59,11 @@ export function MemberPage() {
|
||||
<LoadingProvider><SelectCard/></LoadingProvider>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col" style={{textAlign: 'right', marginTop: '1em'}}>
|
||||
<button className="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#confirm-delete">Supprimer le compte
|
||||
</button>
|
||||
</div>
|
||||
{data.licence == null &&
|
||||
<div className="col" style={{textAlign: 'right', marginTop: '1em'}}>
|
||||
<button className="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#confirm-delete">Supprimer le compte
|
||||
</button>
|
||||
</div>}
|
||||
<ConfirmDialog title="Supprimer le compte" message="Êtes-vous sûr de vouloir supprimer ce compte ?"
|
||||
onConfirm={handleRm}/>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user