fix peer fields updated after save

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-11-18 16:43:09 +03:00
parent a2fb274b86
commit a2a49bdd47
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547

View File

@ -213,7 +213,10 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
var settings *Settings
var peerGroupList []string
var requiresPeerUpdates bool
var newLabel string
var peerLabelChanged bool
var sshChanged bool
var loginExpirationChanged bool
var inactivityExpirationChanged bool
err = am.Store.ExecuteInTransaction(ctx, func(transaction Store) error {
peer, err = transaction.GetPeerByID(ctx, LockingStrengthUpdate, accountID, update.ID)
@ -226,7 +229,7 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
return err
}
peerGroupList, err = getPeerGroupIDs(ctx, am.Store, accountID, update.ID)
peerGroupList, err = getPeerGroupIDs(ctx, transaction, accountID, update.ID)
if err != nil {
return err
}
@ -242,35 +245,24 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
return err
}
newLabel, err = getPeerHostLabel(update.Name, existingLabels)
newLabel, err := getPeerHostLabel(update.Name, existingLabels)
if err != nil {
return err
}
peer.Name = update.Name
peer.DNSLabel = newLabel
peerLabelChanged = true
}
return transaction.SavePeer(ctx, LockingStrengthUpdate, accountID, peer)
})
if err != nil {
return nil, err
}
var sshChanged, peerLabelChanged, loginExpirationChanged, inactivityExpirationChanged bool
if peer.SSHEnabled != update.SSHEnabled {
peer.SSHEnabled = update.SSHEnabled
sshChanged = true
}
if peer.Name != update.Name {
peer.Name = update.Name
peerLabelChanged = true
}
if peer.LoginExpirationEnabled != update.LoginExpirationEnabled {
if !peer.AddedWithSSOLogin() {
return nil, status.Errorf(status.PreconditionFailed, "this peer hasn't been added with the SSO login, therefore the login expiration can't be updated")
return status.Errorf(status.PreconditionFailed, "this peer hasn't been added with the SSO login, therefore the login expiration can't be updated")
}
peer.LoginExpirationEnabled = update.LoginExpirationEnabled
loginExpirationChanged = true
@ -278,12 +270,18 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
if peer.InactivityExpirationEnabled != update.InactivityExpirationEnabled {
if !peer.AddedWithSSOLogin() {
return nil, status.Errorf(status.PreconditionFailed, "this peer hasn't been added with the SSO login, therefore the inactivity expiration can't be updated")
return status.Errorf(status.PreconditionFailed, "this peer hasn't been added with the SSO login, therefore the inactivity expiration can't be updated")
}
peer.InactivityExpirationEnabled = update.InactivityExpirationEnabled
inactivityExpirationChanged = true
}
return transaction.SavePeer(ctx, LockingStrengthUpdate, accountID, peer)
})
if err != nil {
return nil, err
}
if sshChanged {
event := activity.PeerSSHEnabled
if !peer.SSHEnabled {
@ -783,7 +781,7 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
}
}
peerGroupIDs, err := getPeerGroupIDs(ctx, am.Store, accountID, peer.ID)
peerGroupIDs, err := getPeerGroupIDs(ctx, transaction, accountID, peer.ID)
if err != nil {
return err
}