diff --git a/Makefile b/Makefile index 0cfe3a2b..472645a3 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ OAPI_CODEGEN_VERSION ?= v2.0.0 MOCKGEN_VERSION ?= v1.6.0 GOLANGCI_LINT_VERSION ?= v1.55.2 GORELEASER_VERSION ?= v1.22.1 -DEEPCOPY_GEN_VERSION ?= v0.28.3 +DEEPCOPY_GEN_VERSION ?= v0.28.4 ## Tool Installer .PHONY: semver diff --git a/pkg/client/model/model-functions.go b/pkg/client/model/model-functions.go index 18d41e8b..ef11aa25 100644 --- a/pkg/client/model/model-functions.go +++ b/pkg/client/model/model-functions.go @@ -349,11 +349,27 @@ func (ssc *SafeSearchConfig) Equals(o *SafeSearchConfig) bool { } func (pi *ProfileInfo) Equals(o *ProfileInfo) bool { - return pi.Name == o.Name && - pi.Language == o.Language && + return pi.Language == o.Language && pi.Theme == o.Theme } +func (pi *ProfileInfo) ShouldSyncFor(o *ProfileInfo) *ProfileInfo { + if pi.Equals(o) { + return nil + } + merged := &ProfileInfo{Name: pi.Name, Language: pi.Language, Theme: pi.Theme} + if o.Language != "" { + merged.Language = o.Language + } + if o.Theme != "" { + merged.Theme = o.Theme + } + if merged.Name == "" || merged.Language == "" || merged.Theme == "" || merged.Equals(pi) { + return nil + } + return merged +} + func (bss *BlockedServicesSchedule) Equals(o *BlockedServicesSchedule) bool { return utils.JsonEquals(bss, o) } diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go index 893c0d9a..832edcdf 100644 --- a/pkg/sync/sync.go +++ b/pkg/sync/sync.go @@ -465,8 +465,8 @@ func (w *worker) syncGeneralSettings(o *origin, rs *model.ServerStatus, replica if pro, err := replica.ProfileInfo(); err != nil { return err - } else if !o.profileInfo.Equals(pro) { - if err = replica.SetProfileInfo(o.profileInfo); err != nil { + } else if merged := pro.ShouldSyncFor(o.profileInfo); merged != nil { + if err = replica.SetProfileInfo(merged); err != nil { return err } } diff --git a/pkg/sync/sync_test.go b/pkg/sync/sync_test.go index 067e8e6b..354e7ecb 100644 --- a/pkg/sync/sync_test.go +++ b/pkg/sync/sync_test.go @@ -204,8 +204,9 @@ var _ = Describe("Sync", func() { BeforeEach(func() { o = &origin{ profileInfo: &model.ProfileInfo{ - Name: "test", + Name: "origin", Language: "en", + Theme: "auto", }, status: &model.ServerStatus{}, safeSearch: &model.SafeSearchConfig{}, @@ -264,10 +265,44 @@ var _ = Describe("Sync", func() { It("should have profileInfo language changed", func() { o.profileInfo.Language = "de" cl.EXPECT().Parental() - cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Language: "en"}, nil) + cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en"}, nil) cl.EXPECT().SafeSearchConfig().Return(o.safeSearch, nil) cl.EXPECT().SafeBrowsing() - cl.EXPECT().SetProfileInfo(o.profileInfo) + cl.EXPECT().SetProfileInfo(&model.ProfileInfo{ + Language: "de", + Name: "replica", + Theme: "auto", + }) + err := w.syncGeneralSettings(o, rs, cl) + Ω(err).ShouldNot(HaveOccurred()) + }) + It("should not sync profileInfo if language is not set", func() { + o.profileInfo.Language = "" + cl.EXPECT().Parental() + cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en", Theme: "auto"}, nil) + cl.EXPECT().SafeSearchConfig().Return(o.safeSearch, nil) + cl.EXPECT().SafeBrowsing() + cl.EXPECT().SetProfileInfo(o.profileInfo).Times(0) + err := w.syncGeneralSettings(o, rs, cl) + Ω(err).ShouldNot(HaveOccurred()) + }) + It("should not sync profileInfo if language is not set", func() { + o.profileInfo.Language = "" + cl.EXPECT().Parental() + cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en", Theme: "auto"}, nil) + cl.EXPECT().SafeSearchConfig().Return(o.safeSearch, nil) + cl.EXPECT().SafeBrowsing() + cl.EXPECT().SetProfileInfo(o.profileInfo).Times(0) + err := w.syncGeneralSettings(o, rs, cl) + Ω(err).ShouldNot(HaveOccurred()) + }) + It("should not sync profileInfo if theme is not set", func() { + o.profileInfo.Theme = "" + cl.EXPECT().Parental() + cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en", Theme: "auto"}, nil) + cl.EXPECT().SafeSearchConfig().Return(o.safeSearch, nil) + cl.EXPECT().SafeBrowsing() + cl.EXPECT().SetProfileInfo(o.profileInfo).Times(0) err := w.syncGeneralSettings(o, rs, cl) Ω(err).ShouldNot(HaveOccurred()) })