Skip to content

Commit

Permalink
#239 do not sync incomplete profile (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito authored Nov 23, 2023
1 parent fefdda0 commit 012350a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions pkg/client/model/model-functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
41 changes: 38 additions & 3 deletions pkg/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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())
})
Expand Down

0 comments on commit 012350a

Please sign in to comment.