forked from aksdb/CalAnonSync
Prepare customizable title anonymization (#4)
This commit is contained in:
parent
eeb4c430b2
commit
55f4f5f309
|
@ -95,11 +95,7 @@ func runSynchronization(cmd *cobra.Command, args []string) {
|
|||
// Find items we don't know so far and create them.
|
||||
for uid, ewsItem := range relevantEWSItems {
|
||||
if _, ok := calDavItemMap[uid]; !ok {
|
||||
title := s.Anonymize.Title
|
||||
if title == "" {
|
||||
// No anonymization? Fine.
|
||||
title = ewsItem.Subject
|
||||
}
|
||||
title := s.Anonymize.Title.Apply(ewsItem.Subject)
|
||||
ical := CreateICal(ewsItem.Hash(), title, ewsItem.Start, ewsItem.End, ewsItem.IsAllDayEvent)
|
||||
calDavItem := CalDAVItem{HRef: uid + ".ics", ICal: ical}
|
||||
|
||||
|
|
|
@ -22,11 +22,16 @@ type ServerSettings struct {
|
|||
Password string
|
||||
}
|
||||
|
||||
type StringAnonSettings struct {
|
||||
ReplaceWith string
|
||||
Whitelist []string
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
EWS ServerSettings
|
||||
CalDAV ServerSettings
|
||||
Anonymize struct {
|
||||
Title string
|
||||
Title *StringAnonSettings
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,3 +223,11 @@ func runSettingsDecryption(cmd *cobra.Command, args []string) {
|
|||
|
||||
log.Println("Settings decrypted")
|
||||
}
|
||||
|
||||
func (settings *StringAnonSettings) Apply(s string) string {
|
||||
if settings == nil || settings.ReplaceWith == "" {
|
||||
return s
|
||||
}
|
||||
|
||||
return settings.ReplaceWith
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStringAnonSettings_Apply(t *testing.T) {
|
||||
t.Run("Not replaced when nil", func(t *testing.T) {
|
||||
title := "Test"
|
||||
var anonTitle *StringAnonSettings = nil
|
||||
|
||||
if anonTitle.Apply(title) != title {
|
||||
t.Fatal("The title should be unchanged.")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Not replaced when empty", func(t *testing.T) {
|
||||
title := "Test"
|
||||
var anonTitle *StringAnonSettings = &StringAnonSettings{ReplaceWith: ""}
|
||||
|
||||
if anonTitle.Apply(title) != title {
|
||||
t.Fatal("The title should be unchanged.")
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue