Skip to content

Commit

Permalink
Update account attributes only when there is a domain (netbirdio#1701)
Browse files Browse the repository at this point in the history
add log for when a domain is not present
  • Loading branch information
mlsmaycon authored Mar 14, 2024
1 parent 86901e3 commit 68d2b58
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions management/server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,21 @@ func (am *DefaultAccountManager) removeUserFromCache(accountID, userID string) e
func (am *DefaultAccountManager) updateAccountDomainAttributes(account *Account, claims jwtclaims.AuthorizationClaims,
primaryDomain bool,
) error {
account.IsDomainPrimaryAccount = primaryDomain

lowerDomain := strings.ToLower(claims.Domain)
userObj := account.Users[claims.UserId]
if account.Domain != lowerDomain && userObj.Role == UserRoleAdmin {
account.Domain = lowerDomain
}
// prevent updating category for different domain until admin logs in
if account.Domain == lowerDomain {
account.DomainCategory = claims.DomainCategory
if claims.Domain != "" {
account.IsDomainPrimaryAccount = primaryDomain

lowerDomain := strings.ToLower(claims.Domain)
userObj := account.Users[claims.UserId]
if account.Domain != lowerDomain && userObj.Role == UserRoleAdmin {
account.Domain = lowerDomain
}
// prevent updating category for different domain until admin logs in
if account.Domain == lowerDomain {
account.DomainCategory = claims.DomainCategory
}
} else {
log.Errorf("claims don't contain a valid domain, skipping domain attributes update. Received claims: %v", claims)
}

err := am.Store.SaveAccount(account)
Expand Down

0 comments on commit 68d2b58

Please sign in to comment.