From 5fbcdeceac63b94a6d4c0ced784dc2f2971dc0b0 Mon Sep 17 00:00:00 2001 From: crn4 Date: Tue, 19 May 2026 21:41:08 +0200 Subject: [PATCH] more comments --- management/server/store/sql_store.go | 18 ++++++++++ management/server/types/user.go | 54 ---------------------------- 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/management/server/store/sql_store.go b/management/server/store/sql_store.go index 05ba3fd71..5215af545 100644 --- a/management/server/store/sql_store.go +++ b/management/server/store/sql_store.go @@ -3684,6 +3684,14 @@ func (s *SqlStore) assignAccountSeqIDs(ctx context.Context, tx *gorm.DB, account return err } g.AccountSeqID = seq + // Defensive: generateAccountSQLTypes currently aliases the same + // *Group pointer into GroupsG and Groups[id] (so this is a no-op + // today), but mirror the seq anyway so any future divergence in + // how the two collections are populated doesn't silently leave + // the canonical map view stale. + if original, ok := account.Groups[g.ID]; ok && original != nil && original != g { + original.AccountSeqID = seq + } } for _, p := range account.Policies { if p == nil { @@ -3710,6 +3718,13 @@ func (s *SqlStore) assignAccountSeqIDs(ctx context.Context, tx *gorm.DB, account return err } r.AccountSeqID = seq + // Mirror the new seq onto the canonical map view so callers that + // hold the same in-memory account post-Save read a consistent + // AccountSeqID — without this, components/encoder code would see + // 0 for routes saved this transaction until the account is reloaded. + if original, ok := account.Routes[r.ID]; ok && original != nil { + original.AccountSeqID = seq + } } for i := range account.NameServerGroupsG { ng := &account.NameServerGroupsG[i] @@ -3722,6 +3737,9 @@ func (s *SqlStore) assignAccountSeqIDs(ctx context.Context, tx *gorm.DB, account return err } ng.AccountSeqID = seq + if original, ok := account.NameServerGroups[ng.ID]; ok && original != nil { + original.AccountSeqID = seq + } } for _, nr := range account.NetworkResources { if nr == nil { diff --git a/management/server/types/user.go b/management/server/types/user.go index dc601e15b..0b89b8499 100644 --- a/management/server/types/user.go +++ b/management/server/types/user.go @@ -5,7 +5,6 @@ import ( "strings" "time" - "github.com/netbirdio/netbird/management/server/idp" "github.com/netbirdio/netbird/management/server/integration_reference" "github.com/netbirdio/netbird/util/crypt" ) @@ -143,59 +142,6 @@ func (u *User) IsRestrictable() bool { return u.Role == UserRoleUser || u.Role == UserRoleBillingAdmin } -// ToUserInfo converts a User object to a UserInfo object. -func (u *User) ToUserInfo(userData *idp.UserData) (*UserInfo, error) { - autoGroups := u.AutoGroups - if autoGroups == nil { - autoGroups = []string{} - } - - if userData == nil { - - name := u.Name - if u.IsServiceUser { - name = u.ServiceUserName - } - - return &UserInfo{ - ID: u.Id, - Email: u.Email, - Name: name, - Role: string(u.Role), - AutoGroups: u.AutoGroups, - Status: string(UserStatusActive), - IsServiceUser: u.IsServiceUser, - IsBlocked: u.Blocked, - LastLogin: u.GetLastLogin(), - Issued: u.Issued, - PendingApproval: u.PendingApproval, - }, nil - } - if userData.ID != u.Id { - return nil, fmt.Errorf("wrong UserData provided for user %s", u.Id) - } - - userStatus := UserStatusActive - if userData.AppMetadata.WTPendingInvite != nil && *userData.AppMetadata.WTPendingInvite { - userStatus = UserStatusInvited - } - - return &UserInfo{ - ID: u.Id, - Email: userData.Email, - Name: userData.Name, - Role: string(u.Role), - AutoGroups: autoGroups, - Status: string(userStatus), - IsServiceUser: u.IsServiceUser, - IsBlocked: u.Blocked, - LastLogin: u.GetLastLogin(), - Issued: u.Issued, - PendingApproval: u.PendingApproval, - Password: userData.Password, - }, nil -} - // Copy the user func (u *User) Copy() *User { autoGroups := make([]string, len(u.AutoGroups))