mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-16 23:48:31 +02:00
Saving new user to existing account (#310)
Add check if user with account id metadata belongs to account
This commit is contained in:
parent
7e5449fb55
commit
49cca57565
@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -375,6 +376,10 @@ func (am *DefaultAccountManager) handleNewUserAccount(
|
|||||||
if domainAcc != nil {
|
if domainAcc != nil {
|
||||||
account = domainAcc
|
account = domainAcc
|
||||||
account.Users[claims.UserId] = NewRegularUser(claims.UserId)
|
account.Users[claims.UserId] = NewRegularUser(claims.UserId)
|
||||||
|
err = am.Store.SaveAccount(account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed saving updated account")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
account = NewAccount(claims.UserId, lowerDomain)
|
account = NewAccount(claims.UserId, lowerDomain)
|
||||||
account.Users[claims.UserId] = NewAdminUser(claims.UserId)
|
account.Users[claims.UserId] = NewAdminUser(claims.UserId)
|
||||||
@ -417,10 +422,13 @@ func (am *DefaultAccountManager) GetAccountWithAuthorizationClaims(
|
|||||||
if claims.DomainCategory != PrivateCategory {
|
if claims.DomainCategory != PrivateCategory {
|
||||||
return am.GetAccountByUserOrAccountId(claims.UserId, claims.AccountId, claims.Domain)
|
return am.GetAccountByUserOrAccountId(claims.UserId, claims.AccountId, claims.Domain)
|
||||||
} else if claims.AccountId != "" {
|
} else if claims.AccountId != "" {
|
||||||
accountFromID, err := am.GetAccountByUserOrAccountId(claims.UserId, claims.AccountId, claims.Domain)
|
accountFromID, err := am.GetAccountById(claims.AccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if _, ok := accountFromID.Users[claims.UserId]; !ok {
|
||||||
|
return nil, fmt.Errorf("user %s is not part of the account id %s", claims.UserId, claims.AccountId)
|
||||||
|
}
|
||||||
if accountFromID.DomainCategory == PrivateCategory || claims.DomainCategory != PrivateCategory {
|
if accountFromID.DomainCategory == PrivateCategory || claims.DomainCategory != PrivateCategory {
|
||||||
return accountFromID, nil
|
return accountFromID, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user