Simplify peer update condition in DNS management

Refactor the condition for updating account peers to remove redundant checks

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-09-05 21:29:14 +03:00
parent 7523a9e7be
commit 5dbdeff77a
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
2 changed files with 6 additions and 5 deletions

View File

@ -153,9 +153,7 @@ func (am *DefaultAccountManager) SaveDNSSettings(ctx context.Context, accountID
am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupRemovedFromDisabledManagementGroups, meta) am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupRemovedFromDisabledManagementGroups, meta)
} }
updateAccountPeers := (areGroupChangesAffectPeers(account, addedGroups) && anyGroupHasPeers(account, addedGroups)) || if anyGroupHasPeers(account, addedGroups) || anyGroupHasPeers(account, removedGroups) {
areGroupChangesAffectPeers(account, removedGroups) && anyGroupHasPeers(account, removedGroups)
if updateAccountPeers {
am.updateAccountPeers(ctx, account) am.updateAccountPeers(ctx, account)
} }

View File

@ -185,7 +185,9 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
am.StoreEvent(ctx, userID, peer.IP.String(), accountID, event, peer.EventMeta(am.GetDNSDomain())) am.StoreEvent(ctx, userID, peer.IP.String(), accountID, event, peer.EventMeta(am.GetDNSDomain()))
} }
if peer.Name != update.Name { peerLabelUpdated := peer.Name != update.Name
if peerLabelUpdated {
peer.Name = update.Name peer.Name = update.Name
existingLabels := account.getPeerDNSLabels() existingLabels := account.getPeerDNSLabels()
@ -226,7 +228,8 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
} }
expired, _ := peer.LoginExpired(account.Settings.PeerLoginExpiration) expired, _ := peer.LoginExpired(account.Settings.PeerLoginExpiration)
if expired && peer.LoginExpirationEnabled {
if peerLabelUpdated || (expired && peer.LoginExpirationEnabled) {
am.updateAccountPeers(ctx, account) am.updateAccountPeers(ctx, account)
} }