feat: upgrade club groupe name in kc when club is rename
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 10m13s
All checks were successful
Deploy Production Server / if_merged (pull_request) Successful in 10m13s
This commit is contained in:
parent
9ab50238b9
commit
be2f01c070
@ -28,6 +28,7 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@WithSession
|
||||
@ -366,17 +367,23 @@ public class AffiliationService {
|
||||
}
|
||||
|
||||
private Uni<ClubModel> acceptOld(AffiliationRequestSaveForm form, AffiliationRequestModel model, ClubModel club) {
|
||||
AtomicBoolean nameChange = new AtomicBoolean(false);
|
||||
LOGGER.debug("Old Club Accepted");
|
||||
return Uni.createFrom().nullItem()
|
||||
.chain(() -> {
|
||||
club.setName(form.getName());
|
||||
if (!form.getName().equals(club.getName())) {
|
||||
club.setName(form.getName());
|
||||
nameChange.set(true);
|
||||
}
|
||||
club.setCountry("FR");
|
||||
club.setStateId(form.getState_id());
|
||||
club.setAddress(form.getAddress());
|
||||
club.setContact_intern(form.getContact());
|
||||
return Panache.withTransaction(() -> clubRepository.persist(club)
|
||||
.chain(() -> repository.persist(new AffiliationModel(null, club, model.getSaison())))
|
||||
.chain(() -> repositoryRequest.delete(model)));
|
||||
.chain(() -> repositoryRequest.delete(model)))
|
||||
.call(() -> nameChange.get() ? keycloakService.updateGroupFromClub(club) // update group in keycloak
|
||||
: Uni.createFrom().nullItem());
|
||||
})
|
||||
.map(__ -> club);
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
|
||||
@ -193,12 +194,17 @@ public class ClubService {
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, FullClubForm input) {
|
||||
AtomicBoolean nameChange = new AtomicBoolean(false);
|
||||
|
||||
return repository.findById(id).call(m -> Mutiny.fetch(m.getContact()))
|
||||
.onItem().transformToUni(Unchecked.function(m -> {
|
||||
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
|
||||
};
|
||||
|
||||
m.setName(input.getName());
|
||||
if (!input.getName().equals(m.getName())) {
|
||||
m.setName(input.getName());
|
||||
nameChange.set(true);
|
||||
}
|
||||
m.setCountry(input.getCountry());
|
||||
m.setInternational(input.isInternational());
|
||||
|
||||
@ -228,6 +234,8 @@ public class ClubService {
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(m)).call(() -> ls.append());
|
||||
}))
|
||||
.call(clubModel -> nameChange.get() ? keycloakService.updateGroupFromClub(clubModel) // update group in keycloak
|
||||
: Uni.createFrom().nullItem())
|
||||
.invoke(membreModel -> SReqClub.sendIfNeed(serverCustom.clients,
|
||||
SimpleClubModel.fromModel(membreModel)))
|
||||
.map(__ -> "OK");
|
||||
|
||||
@ -85,6 +85,31 @@ public class KeycloakService {
|
||||
return Uni.createFrom().item(club::getClubId);
|
||||
}
|
||||
|
||||
public Uni<String> updateGroupFromClub(ClubModel club) {
|
||||
if (club.getClubId() == null) {
|
||||
return getGroupFromClub(club);
|
||||
} else {
|
||||
LOGGER.infof("Updating name of club group %d-%s...", club.getId(), club.getName());
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
GroupRepresentation clubGroup =
|
||||
keycloak.realm(realm).groups().groups().stream().filter(g -> g.getName().equals("club"))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new KeycloakException("Fail to fetch group %s".formatted("club")));
|
||||
|
||||
keycloak.realm(realm).groups().group(clubGroup.getId()).getSubGroups(0, 1000, true).stream()
|
||||
.filter(g -> g.getName().startsWith(club.getId() + "-")).findAny()
|
||||
.ifPresent(groupRepresentation -> {
|
||||
groupRepresentation.setName(club.getId() + "-" + club.getName());
|
||||
keycloak.realm(realm).groups().group(groupRepresentation.getId())
|
||||
.update(groupRepresentation);
|
||||
});
|
||||
|
||||
return club.getClubId();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<String> getUserFromMember(MembreModel membreModel) {
|
||||
if (membreModel.getUserId() == null) {
|
||||
return Uni.createFrom()
|
||||
@ -199,16 +224,16 @@ public class KeycloakService {
|
||||
|
||||
public Uni<String> initCompte(long id) {
|
||||
return membreService.getById(id).invoke(Unchecked.consumer(membreModel -> {
|
||||
if (membreModel.getUserId() != null)
|
||||
throw new KeycloakException("User already linked to the user id=" + id);
|
||||
if (membreModel.getEmail() == null)
|
||||
throw new KeycloakException("User email is null");
|
||||
if (membreModel.getFname() == null || membreModel.getLname() == null)
|
||||
throw new KeycloakException("User name is null");
|
||||
})).chain(membreModel -> creatUser(membreModel).chain(user -> {
|
||||
LOGGER.infof("Set user id %s to membre %s", user.getId(), membreModel.getId());
|
||||
return membreService.setUserId(membreModel.getId(), user.getId()).map(__ -> user.getId());
|
||||
}));
|
||||
if (membreModel.getUserId() != null)
|
||||
throw new KeycloakException("User already linked to the user id=" + id);
|
||||
if (membreModel.getEmail() == null)
|
||||
throw new KeycloakException("User email is null");
|
||||
if (membreModel.getFname() == null || membreModel.getLname() == null)
|
||||
throw new KeycloakException("User name is null");
|
||||
})).chain(membreModel -> creatUser(membreModel).chain(user -> {
|
||||
LOGGER.infof("Set user id %s to membre %s", user.getId(), membreModel.getId());
|
||||
return membreService.setUserId(membreModel.getId(), user.getId()).map(__ -> user.getId());
|
||||
}));
|
||||
}
|
||||
|
||||
private Uni<UserRepresentation> creatUser(MembreModel membreModel) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user