feat: add club member's gestion page
This commit is contained in:
@@ -2,8 +2,7 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.KeycloakException;
|
||||
import fr.titionfire.ffsaf.utils.RequiredAction;
|
||||
import fr.titionfire.ffsaf.utils.*;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
@@ -21,6 +20,7 @@ import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -86,13 +86,42 @@ public class KeycloakService {
|
||||
})));
|
||||
}
|
||||
|
||||
public Uni<UserCompteState> fetchCompte(String id) {
|
||||
public Uni<?> setEmail(String userId, String email) {
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
UserResource user = keycloak.realm(realm).users().get(userId);
|
||||
UserRepresentation user2 = user.toRepresentation();
|
||||
if (email.equals(user2.getEmail()))
|
||||
return "";
|
||||
user2.setEmail(email);
|
||||
user2.setRequiredActions(List.of(RequiredAction.VERIFY_EMAIL.name()));
|
||||
user.update(user2);
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<?> setAutoRoleMembre(String id, RoleAsso role, GradeArbitrage gradeArbitrage) {
|
||||
List<String> toRemove = new ArrayList<>(List.of("club_president", "club_tresorier", "club_secretaire", "asseseur", "arbitre"));
|
||||
List<String> toAdd = new ArrayList<>();
|
||||
|
||||
switch (role) {
|
||||
case PRESIDENT -> toAdd.add("club_president");
|
||||
case TRESORIER -> toAdd.add("club_tresorier");
|
||||
case SECRETAIRE -> toAdd.add("club_secretaire");
|
||||
}
|
||||
switch (gradeArbitrage) {
|
||||
case ARBITRE -> toAdd.addAll(List.of("asseseur", "arbitre"));
|
||||
case ASSESSEUR -> toAdd.add("asseseur");
|
||||
}
|
||||
toRemove.removeAll(toAdd);
|
||||
|
||||
return updateRole(id, toAdd, toRemove);
|
||||
}
|
||||
|
||||
public Uni<Pair<UserResource, UserCompteState>> fetchCompte(String id) {
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
UserResource user = keycloak.realm(realm).users().get(id);
|
||||
UserRepresentation user2 = user.toRepresentation();
|
||||
return new UserCompteState(user2.isEnabled(), user2.getUsername(), user2.isEmailVerified(),
|
||||
user.roles().realmLevel().listEffective().stream().map(RoleRepresentation::getName).toList(),
|
||||
user.groups().stream().map(GroupRepresentation::getName).toList());
|
||||
return new Pair<>(user, new UserCompteState(user2.isEnabled(), user2.getUsername(), user2.isEmailVerified())) ;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -182,7 +211,6 @@ public class KeycloakService {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record UserCompteState(Boolean enabled, String login, Boolean emailVerified, List<String> realmRoles,
|
||||
List<String> groups) {
|
||||
public record UserCompteState(Boolean enabled, String login, Boolean emailVerified) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user