From ef3c0da0cb67067090845a3a51f5cf575e636ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 20 Jan 2026 11:01:49 +0100 Subject: [PATCH] Assing the opencloudUser to the users so they get a personal space --- .../multi-tenancy/initialize_users.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/devtools/deployments/multi-tenancy/initialize_users.go b/devtools/deployments/multi-tenancy/initialize_users.go index 245a2569b3..ebbbbb1073 100644 --- a/devtools/deployments/multi-tenancy/initialize_users.go +++ b/devtools/deployments/multi-tenancy/initialize_users.go @@ -90,6 +90,7 @@ func main() { } resetAllUserPasswords() + setUserRoles() } func createUser(client *libregraph.APIClient, user libregraph.EducationUser) (string, error) { @@ -112,6 +113,34 @@ func createTenant(client *libregraph.APIClient, tenant libregraph.EducationSchoo return newTenant.GetId(), nil } +func setUserRoles() { + tls := tls.Config{InsecureSkipVerify: true} + restyClient := resty.New().SetTLSClientConfig(&tls) + client := gocloak.NewClient("https://keycloak.opencloud.test") + client.SetRestyClient(restyClient) + ctx := context.Background() + token, err := client.LoginAdmin(ctx, "kcadmin", "admin", "master") + if err != nil { + fmt.Printf("Failed to login: %s\n", err) + panic("Something wrong with the credentials or url") + } + + role, _ := client.GetRealmRole(ctx, token.AccessToken, "openCloud", "opencloudUser") + users, err := client.GetUsers(ctx, token.AccessToken, "openCloud", gocloak.GetUsersParams{}) + if err != nil { + fmt.Printf("%s\n", err) + panic("Oh no!, failed to list users :(") + } + for _, user := range users { + err := client.AddRealmRoleToUser(ctx, token.AccessToken, "openCloud", *user.ID, []gocloak.Role{ + *role, + }) + if err != nil { + fmt.Printf("Failed to assign role to user %s: %s\n", *user.Username, err) + } + } +} + func resetAllUserPasswords() { tls := tls.Config{InsecureSkipVerify: true} restyClient := resty.New().SetTLSClientConfig(&tls)