mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-17 18:41:41 +02:00
Refactor group changes
This commit is contained in:
@ -165,7 +165,12 @@ func (am *DefaultAccountManager) SaveGroups(ctx context.Context, accountID, user
|
|||||||
eventsToStore = append(eventsToStore, events...)
|
eventsToStore = append(eventsToStore, events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccountPeers := areGroupChangesAffectPeers(account, newGroups)
|
newGroupIDs := make([]string, 0, len(newGroups))
|
||||||
|
for _, newGroup := range newGroups {
|
||||||
|
newGroupIDs = append(newGroupIDs, newGroup.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAccountPeers := areGroupChangesAffectPeers(account, newGroupIDs)
|
||||||
if updateAccountPeers {
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
}
|
}
|
||||||
@ -324,7 +329,7 @@ func (am *DefaultAccountManager) GroupAddPeer(ctx context.Context, accountID, gr
|
|||||||
group.Peers = append(group.Peers, peerID)
|
group.Peers = append(group.Peers, peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccountPeers := areGroupChangesAffectPeers(account, []*nbgroup.Group{group})
|
updateAccountPeers := areGroupChangesAffectPeers(account, []string{group.ID})
|
||||||
if updateAccountPeers {
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
}
|
}
|
||||||
@ -355,7 +360,7 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
|
|||||||
return status.Errorf(status.NotFound, "group with ID %s not found", groupID)
|
return status.Errorf(status.NotFound, "group with ID %s not found", groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccountPeers := areGroupChangesAffectPeers(account, []*nbgroup.Group{group})
|
updateAccountPeers := areGroupChangesAffectPeers(account, []string{group.ID})
|
||||||
if updateAccountPeers {
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
}
|
}
|
||||||
@ -376,15 +381,15 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func areGroupChangesAffectPeers(account *Account, groups []*nbgroup.Group) bool {
|
func areGroupChangesAffectPeers(account *Account, groupIDs []string) bool {
|
||||||
for _, group := range groups {
|
for _, groupID := range groupIDs {
|
||||||
if linked, _ := isGroupLinkedToDns(account.NameServerGroups, group.ID); linked {
|
if linked, _ := isGroupLinkedToDns(account.NameServerGroups, groupID); linked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if linked, _ := isGroupLinkedToPolicy(account.Policies, group.ID); linked {
|
if linked, _ := isGroupLinkedToPolicy(account.Policies, groupID); linked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if linked, _ := isGroupLinkedToRoute(account.Routes, group.ID); linked {
|
if linked, _ := isGroupLinkedToRoute(account.Routes, groupID); linked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user