From 0106a95f7a28e2135d994e695ec758f7bcb40f2d Mon Sep 17 00:00:00 2001 From: Bethuel Mmbaga Date: Tue, 22 Oct 2024 13:29:17 +0300 Subject: [PATCH] lock account and use transaction (#2767) Signed-off-by: bcmmbaga --- management/server/account.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/management/server/account.go b/management/server/account.go index cca3b4e52..b49b82f91 100644 --- a/management/server/account.go +++ b/management/server/account.go @@ -2012,10 +2012,10 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st jwtGroupsNames := extractJWTGroups(ctx, settings.JWTGroupsClaimName, claims) - unlockPeer := am.Store.AcquireWriteLockByUID(ctx, accountID) + unlockAccount := am.Store.AcquireWriteLockByUID(ctx, accountID) defer func() { - if unlockPeer != nil { - unlockPeer() + if unlockAccount != nil { + unlockAccount() } }() @@ -2024,12 +2024,12 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st var hasChanges bool var user *User err = am.Store.ExecuteInTransaction(ctx, func(transaction Store) error { - user, err = am.Store.GetUserByUserID(ctx, LockingStrengthShare, claims.UserId) + user, err = transaction.GetUserByUserID(ctx, LockingStrengthShare, claims.UserId) if err != nil { return fmt.Errorf("error getting user: %w", err) } - groups, err := am.Store.GetAccountGroups(ctx, accountID) + groups, err := transaction.GetAccountGroups(ctx, accountID) if err != nil { return fmt.Errorf("error getting account groups: %w", err) } @@ -2087,8 +2087,8 @@ func (am *DefaultAccountManager) syncJWTGroups(ctx context.Context, accountID st return fmt.Errorf("error incrementing network serial: %w", err) } } - unlockPeer() - unlockPeer = nil + unlockAccount() + unlockAccount = nil return nil })