mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 17:58:02 +02:00
fix sonar
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
664d1388aa
commit
ab00c41dad
@ -89,6 +89,10 @@ func (am *DefaultAccountManager) SaveGroups(ctx context.Context, accountID, user
|
|||||||
return status.NewUserNotPartOfAccountError()
|
return status.NewUserNotPartOfAccountError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.IsRegularUser() {
|
||||||
|
return status.NewAdminPermissionError()
|
||||||
|
}
|
||||||
|
|
||||||
var eventsToStore []func()
|
var eventsToStore []func()
|
||||||
var groupsToSave []*nbgroup.Group
|
var groupsToSave []*nbgroup.Group
|
||||||
var updateAccountPeers bool
|
var updateAccountPeers bool
|
||||||
@ -213,6 +217,10 @@ func (am *DefaultAccountManager) DeleteGroup(ctx context.Context, accountID, use
|
|||||||
return status.NewUserNotPartOfAccountError()
|
return status.NewUserNotPartOfAccountError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.IsRegularUser() {
|
||||||
|
return status.NewAdminPermissionError()
|
||||||
|
}
|
||||||
|
|
||||||
var group *nbgroup.Group
|
var group *nbgroup.Group
|
||||||
|
|
||||||
err = am.Store.ExecuteInTransaction(ctx, func(transaction Store) error {
|
err = am.Store.ExecuteInTransaction(ctx, func(transaction Store) error {
|
||||||
@ -260,6 +268,10 @@ func (am *DefaultAccountManager) DeleteGroups(ctx context.Context, accountID, us
|
|||||||
return status.NewUserNotPartOfAccountError()
|
return status.NewUserNotPartOfAccountError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.IsRegularUser() {
|
||||||
|
return status.NewAdminPermissionError()
|
||||||
|
}
|
||||||
|
|
||||||
var allErrors error
|
var allErrors error
|
||||||
var groupIDsToDelete []string
|
var groupIDsToDelete []string
|
||||||
var deletedGroups []*nbgroup.Group
|
var deletedGroups []*nbgroup.Group
|
||||||
@ -438,6 +450,11 @@ func validateDeleteGroup(ctx context.Context, transaction Store, group *nbgroup.
|
|||||||
return &GroupLinkError{"user", linkedUser.Id}
|
return &GroupLinkError{"user", linkedUser.Id}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return checkGroupLinkedToSettings(ctx, transaction, group)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkGroupLinkedToSettings verifies if a group is linked to any settings in the account.
|
||||||
|
func checkGroupLinkedToSettings(ctx context.Context, transaction Store, group *nbgroup.Group) error {
|
||||||
dnsSettings, err := transaction.GetAccountDNSSettings(ctx, LockingStrengthShare, group.AccountID)
|
dnsSettings, err := transaction.GetAccountDNSSettings(ctx, LockingStrengthShare, group.AccountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -452,10 +469,8 @@ func validateDeleteGroup(ctx context.Context, transaction Store, group *nbgroup.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.Extra != nil {
|
if settings.Extra != nil && slices.Contains(settings.Extra.IntegratedValidatorGroups, group.ID) {
|
||||||
if slices.Contains(settings.Extra.IntegratedValidatorGroups, group.ID) {
|
return &GroupLinkError{"integrated validator", group.Name}
|
||||||
return &GroupLinkError{"integrated validator", group.Name}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -55,8 +55,7 @@ func (g *Group) IsGroupAll() bool {
|
|||||||
return g.Name == "All"
|
return g.Name == "All"
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddPeer adds peerID to Peers if not already present,
|
// AddPeer adds peerID to Peers if not present, returning true if added.
|
||||||
// returning true if added.
|
|
||||||
func (g *Group) AddPeer(peerID string) bool {
|
func (g *Group) AddPeer(peerID string) bool {
|
||||||
if peerID == "" {
|
if peerID == "" {
|
||||||
return false
|
return false
|
||||||
@ -72,8 +71,7 @@ func (g *Group) AddPeer(peerID string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemovePeer removes peerID from Peers if present,
|
// RemovePeer removes peerID from Peers if present, returning true if removed.
|
||||||
// returning true if removed.
|
|
||||||
func (g *Group) RemovePeer(peerID string) bool {
|
func (g *Group) RemovePeer(peerID string) bool {
|
||||||
for i, itemID := range g.Peers {
|
for i, itemID := range g.Peers {
|
||||||
if itemID == peerID {
|
if itemID == peerID {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user