diff --git a/management/server/peer.go b/management/server/peer.go index 18d3f0e0183..33975cdda4e 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -5,9 +5,10 @@ import ( "strings" "time" - "github.com/netbirdio/management-integrations/additions" "github.com/rs/xid" + "github.com/netbirdio/management-integrations/additions" + "github.com/netbirdio/netbird/management/server/activity" nbpeer "github.com/netbirdio/netbird/management/server/peer" "github.com/netbirdio/netbird/management/server/status" @@ -440,6 +441,14 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *nbpeer.P } } + if addedByUser { + user, err := account.FindUser(userID) + if err != nil { + return nil, nil, status.Errorf(status.Internal, "couldn't find user") + } + user.updateLastLogin(newPeer.LastLogin) + } + account.Peers[newPeer.ID] = newPeer account.Network.IncSerial() err = am.Store.SaveAccount(account) @@ -550,6 +559,13 @@ func (am *DefaultAccountManager) LoginPeer(login PeerLogin) (*nbpeer.Peer, *Netw updateRemotePeers = true shouldStoreAccount = true + // sync user last login with peer last login + user, err := account.FindUser(login.UserID) + if err != nil { + return nil, nil, status.Errorf(status.Internal, "couldn't find user") + } + user.updateLastLogin(peer.LastLogin) + am.StoreEvent(login.UserID, peer.ID, account.Id, activity.UserLoggedInPeer, peer.EventMeta(am.GetDNSDomain())) } diff --git a/management/server/user.go b/management/server/user.go index 028f7a25ba7..d48299b1e16 100644 --- a/management/server/user.go +++ b/management/server/user.go @@ -101,6 +101,10 @@ func (u *User) LastDashboardLoginChanged(LastLogin time.Time) bool { return LastLogin.After(u.LastLogin) && !u.LastLogin.IsZero() } +func (u *User) updateLastLogin(login time.Time) { + u.LastLogin = login +} + // HasAdminPower returns true if the user has admin or owner roles, false otherwise func (u *User) HasAdminPower() bool { return u.Role == UserRoleAdmin || u.Role == UserRoleOwner