[v11.1.x] OrgSync: Do not set default Organization for a user to a non-existent Organization (#94551)
OrgSync: Do not set default Organization for a user to a non-existent Organization (#94537)
Do not set default org for a user to a missing org
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
(cherry picked from commit c872cad879)
This commit is contained in:
@@ -82,18 +82,25 @@ func (s *OrgSync) SyncOrgRolesHook(ctx context.Context, id *authn.Identity, _ *a
|
||||
orgIDs := make([]int64, 0, len(id.OrgRoles))
|
||||
// add any new org roles
|
||||
for orgId, orgRole := range id.OrgRoles {
|
||||
orgIDs = append(orgIDs, orgId)
|
||||
if _, exists := handledOrgIds[orgId]; exists {
|
||||
orgIDs = append(orgIDs, orgId)
|
||||
continue
|
||||
}
|
||||
|
||||
// add role
|
||||
cmd := &org.AddOrgUserCommand{UserID: userID, Role: orgRole, OrgID: orgId}
|
||||
err := s.orgService.AddOrgUser(ctx, cmd)
|
||||
if err != nil && !errors.Is(err, org.ErrOrgNotFound) {
|
||||
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
ctxLogger.Error("Failed to update active org for user", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
orgIDs = append(orgIDs, orgId)
|
||||
}
|
||||
|
||||
// delete any removed org roles
|
||||
|
||||
Reference in New Issue
Block a user