Files
upstream-corteza/server/pkg/provision/user_groups.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

79 lines
1.5 KiB
Go

package provision
import (
"context"
"os"
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/options"
"go.uber.org/zap"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/types"
)
func setDefaultUserGroupRefs(ctx context.Context, log *zap.Logger, s store.Storer, authOpt options.AuthOpt) (err error) {
log.Info("provision start")
defer log.Info("provision end")
h, ok := os.LookupEnv("AUTH_DEFAULT_USER_GROUP")
if !ok {
h = "default-root"
}
ug, err := store.LookupUserGroupByHandle(ctx, s, h)
if err != nil {
if errors.IsNotFound(err) {
// Missing/deleted group; nothing to backfill, don't abort provisioning
log.Warn("default user group not found or deleted, skipping user/auth-client backfill", zap.String("handle", h))
return nil
}
return
}
// ---
// Users
// ---
uu, _, err := store.SearchUsers(ctx, s, types.UserFilter{
Kind: types.NormalUser,
})
if err != nil {
return
}
for _, u := range uu {
if u.UserGroupID != 0 {
continue
}
u.UserGroupID = ug.ID
err = store.UpdateUser(ctx, s, u)
if err != nil {
return
}
}
// ---
// auth clients
// ---
cc, _, err := store.SearchAuthClients(ctx, s, types.AuthClientFilter{})
if err != nil {
return
}
for _, c := range cc {
if c.Security.UserGroup != 0 {
continue
}
c.Security.UserGroup = ug.ID
err = store.UpdateAuthClient(ctx, s, c)
if err != nil {
return
}
}
return
}