mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-16 10:08:12 +02:00
[management] Remove deleted user peers from groups on user deletion (#4121)
Refactors peer deletion to centralize group cleanup logic, ensuring deleted peers are consistently removed from all groups in one place. - Removed redundant group removal code from DefaultAccountManager.DeletePeer - Added group removal logic inside deletePeers to handle both single and multiple peer deletions
This commit is contained in:
@ -364,19 +364,6 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
groups, err := transaction.GetPeerGroups(ctx, store.LockingStrengthUpdate, accountID, peerID)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to get peer groups: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, group := range groups {
|
|
||||||
group.RemovePeer(peerID)
|
|
||||||
err = transaction.SaveGroup(ctx, store.LockingStrengthUpdate, group)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to save group: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsToStore, err = deletePeers(ctx, am, transaction, accountID, userID, []*nbpeer.Peer{peer})
|
eventsToStore, err = deletePeers(ctx, am, transaction, accountID, userID, []*nbpeer.Peer{peer})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
@ -1517,13 +1504,26 @@ func deletePeers(ctx context.Context, am *DefaultAccountManager, transaction sto
|
|||||||
}
|
}
|
||||||
dnsDomain := am.GetDNSDomain(settings)
|
dnsDomain := am.GetDNSDomain(settings)
|
||||||
|
|
||||||
for _, peer := range peers {
|
network, err := transaction.GetAccountNetwork(ctx, store.LockingStrengthShare, accountID)
|
||||||
if err := am.integratedPeerValidator.PeerDeleted(ctx, accountID, peer.ID); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
network, err := transaction.GetAccountNetwork(ctx, store.LockingStrengthShare, accountID)
|
for _, peer := range peers {
|
||||||
|
groups, err := transaction.GetPeerGroups(ctx, store.LockingStrengthUpdate, accountID, peer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get peer groups: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
group.RemovePeer(peer.ID)
|
||||||
|
err = transaction.SaveGroup(ctx, store.LockingStrengthUpdate, group)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to save group: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := am.integratedPeerValidator.PeerDeleted(ctx, accountID, peer.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user