From 49b0ce818024e70e17abf82593854a432fc6b40b Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Wed, 16 Nov 2022 18:14:02 +0500 Subject: [PATCH] ipn/ipnlocal: update profile on server sent profile changes We were not updating the LoginProfile.UserProfile when a netmap updated the UserProfile (e.g. when a node was tagged via the admin panel). Updates #713 Signed-off-by: Maisem Ali --- ipn/ipnlocal/local.go | 8 ++++---- ipn/ipnlocal/profiles.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index c0187d8ac..7df12245d 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -3300,10 +3300,10 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) { if login == "" { login = "" } - if cp := b.pm.CurrentProfile(); cp.ID != "" && cp.UserProfile.ID == 0 { - // Migration to profiles: we didn't use to persist - // the UserProfile, so if we don't have one, fill it - // in from the NetworkMap. + if cp := b.pm.CurrentProfile(); cp.ID != "" && cp.UserProfile.ID != up.ID { + // If the current profile doesn't match the + // network map's user profile, then we need to + // update the persisted UserProfile to match. prefs := b.pm.CurrentPrefs().AsStruct() prefs.Persist.UserProfile = up b.pm.SetPrefs(prefs.View()) diff --git a/ipn/ipnlocal/profiles.go b/ipn/ipnlocal/profiles.go index 1fe6ab1ed..cb06d625a 100644 --- a/ipn/ipnlocal/profiles.go +++ b/ipn/ipnlocal/profiles.go @@ -126,6 +126,7 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView) error { up.DisplayName = up.LoginName } cp := pm.currentProfile + wasNamedWithLoginName := cp.Name == cp.UserProfile.LoginName if pm.isNewProfile { pm.isNewProfile = false cp.ID, cp.Key = newUnusedID(pm.knownProfiles) @@ -135,6 +136,9 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView) error { } else { cp.UserProfile = ps.UserProfile } + if wasNamedWithLoginName { + cp.Name = ps.LoginName + } pm.knownProfiles[cp.ID] = cp if err := pm.writeKnownProfiles(); err != nil { return err