feat: add set userId
This commit is contained in:
parent
b4e0d0fa3d
commit
58c2134e35
@ -104,7 +104,7 @@ public class KeycloakService {
|
||||
public Uni<?> updateRole(String id, List<String> toAdd, List<String> toRemove) {
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
RoleScopeResource resource = keycloak.realm(realm).users().get(id).roles().realmLevel();
|
||||
List<RoleRepresentation> roles = keycloak.realm(realm) .roles().list();
|
||||
List<RoleRepresentation> roles = keycloak.realm(realm).roles().list();
|
||||
resource.add(roles.stream().filter(r -> toAdd.contains(r.getName())).toList());
|
||||
resource.remove(roles.stream().filter(r -> toRemove.contains(r.getName())).toList());
|
||||
return "OK";
|
||||
@ -127,9 +127,18 @@ public class KeycloakService {
|
||||
}
|
||||
|
||||
private Uni<UserRepresentation> creatUser(MembreModel membreModel) {
|
||||
String login = makeLogin(membreModel);
|
||||
LOGGER.infof("Creation of user %s...", login);
|
||||
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||
String login;
|
||||
int i = 1;
|
||||
do {
|
||||
login = makeLogin(membreModel);
|
||||
if (i > 1) {
|
||||
login += i;
|
||||
}
|
||||
i++;
|
||||
} while (!keycloak.realm(realm).users().searchByUsername(login, true).isEmpty());
|
||||
LOGGER.infof("Creation of user %s...", login);
|
||||
|
||||
UserRepresentation user = new UserRepresentation();
|
||||
user.setUsername(login);
|
||||
user.setFirstName(membreModel.getFname());
|
||||
@ -145,13 +154,18 @@ public class KeycloakService {
|
||||
throw new KeycloakException("Fail to creat user %s (reason=%s)".formatted(login, response.getStatusInfo().getReasonPhrase()));
|
||||
}
|
||||
|
||||
return getUser(login).orElseThrow(() -> new KeycloakException("Fail to fetch user %s".formatted(login)));
|
||||
String finalLogin = login;
|
||||
return getUser(login).orElseThrow(() -> new KeycloakException("Fail to fetch user %s".formatted(finalLogin)));
|
||||
})
|
||||
.invoke(user -> membreModel.setUserId(user.getId()))
|
||||
.call(user -> membreService.setUserId(membreModel.getId(), user.getId()))
|
||||
.call(user -> setClubGroupMembre(membreModel, membreModel.getClub()));
|
||||
}
|
||||
|
||||
public Uni<?> setId(long id, String nid) {
|
||||
return membreService.setUserId(id, nid).map(__ -> "OK");
|
||||
}
|
||||
|
||||
private Optional<UserRepresentation> getUser(String username) {
|
||||
List<UserRepresentation> users = keycloak.realm(realm).users().searchByUsername(username, true);
|
||||
|
||||
|
||||
@ -33,6 +33,13 @@ public class CompteEndpoints {
|
||||
return service.initCompte(id);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}/setUUID/{nid}")
|
||||
@RolesAllowed("federation_admin")
|
||||
public Uni<?> initCompte(@PathParam("id") long id, @PathParam("nid") String nid) {
|
||||
return service.setId(id, nid);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/roles")
|
||||
@RolesAllowed("federation_admin")
|
||||
|
||||
@ -278,9 +278,31 @@ function CompteInfo({userData}) {
|
||||
}
|
||||
)
|
||||
}
|
||||
const sendId = (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
toast.promise(
|
||||
apiAxios.put(`/compte/${userData.id}/setUUID/${event.target.uuid?.value}`),
|
||||
{
|
||||
pending: "Définition de l'identifient en cours",
|
||||
success: "Identifient défini avec succès 🎉",
|
||||
error: "Échec de la définition de l'identifient 😕 "
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return <div className="card mb-4">
|
||||
<div className="card-header">Compte</div>
|
||||
<div className="card-header">
|
||||
<div className="btn-group dropend">
|
||||
<div className="dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Compte
|
||||
</div>
|
||||
<ul className="dropdown-menu">
|
||||
<li><button type="button" className="btn btn-primary" data-bs-toggle="modal"
|
||||
data-bs-target="#comptIdModal">Définir l'id du compte</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body text-center">
|
||||
{userData.userId
|
||||
? <CompteInfoContent userData={userData}/>
|
||||
@ -299,6 +321,28 @@ function CompteInfo({userData}) {
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
<div className="modal fade" id="comptIdModal" tabIndex="-1" aria-labelledby="comptIdModalLabel" aria-hidden="true">
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<form onSubmit={sendId}>
|
||||
<div className="modal-header">
|
||||
<h1 className="modal-title fs-5" id="comptIdModalLabel">Entré l'UUID du compte</h1>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal"
|
||||
aria-label="Close"></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<h5>Attention ne changée l'id d'un membre que si vous êtes sûr de ce que vos faites...</h5>
|
||||
<input type="text" className="form-control" placeholder="uuid" name="uuid"
|
||||
defaultValue={userData.userId}/>
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button type="reset" className="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
|
||||
<button type="submit" className="btn btn-primary">Appliquer</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user