Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transformer to keep original event link #216

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example.sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ transformations:
config:
NewTitle: "[Synchronisierter Termin]"
- name: KeepMeetingLink
- name: AddOriginalLink
# Do not use KeepAttendees when the Outlook Adapter is used as a sink. There is no way to suppress mail invitations
- name: KeepAttendees
config:
Expand Down
1 change: 1 addition & 0 deletions internal/adapter/google/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func calendarEventToEvent(e *calendar.Event, adapterSourceID string) models.Even
Reminders: reminders,
MeetingLink: e.HangoutLink,
Accepted: hasEventAccepted,
HTMLLink: e.HtmlLink,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/adapter/outlook_http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (o OutlookClient) outlookEventToEvent(oe Event, adapterSourceID string) (e
Reminders: reminders,
MeetingLink: oe.OnlineMeetingUrl,
Accepted: hasEventAccepted,
HTMLLink: oe.HtmlLink,
}

if oe.IsAllDay {
Expand Down
1 change: 1 addition & 0 deletions internal/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Event struct {
Reminders Reminders
MeetingLink string
Accepted bool
HTMLLink string
}

type Reminders []Reminder
Expand Down
2 changes: 2 additions & 0 deletions internal/sync/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
"PrefixTitle": &transformation.PrefixTitle{Prefix: ""},
"KeepTitle": &transformation.KeepTitle{},
"KeepMeetingLink": &transformation.KeepMeetingLink{},
"AddOriginalLink": &transformation.AddOriginalLink{},
"KeepDescription": &transformation.KeepDescription{},
"KeepLocation": &transformation.KeepLocation{},
"KeepAttendees": &transformation.KeepAttendees{UseEmailAsDisplayName: false},
Expand All @@ -49,6 +50,7 @@ var (
"KeepReminders",
"KeepDescription",
"KeepMeetingLink",
"AddOriginalLink",
"KeepTitle",
"PrefixTitle",
"ReplaceTitle",
Expand Down
19 changes: 19 additions & 0 deletions internal/transformation/addOriginalLink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package transformation

import (
"fmt"
"github.com/inovex/CalendarSync/internal/models"
)

type AddOriginalLink struct{}

func (t *AddOriginalLink) Name() string {
return "AddOriginalLink"
}

func (t *AddOriginalLink) Transform(source models.Event, sink models.Event) (models.Event, error) {
if len(source.HTMLLink) > 0 {
sink.Description = fmt.Sprintf("original event link: %s\n\n############\n%s", source.HTMLLink, sink.Description)
}
return sink, nil
}
92 changes: 92 additions & 0 deletions internal/transformation/addOriginalLink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package transformation

import (
"testing"

"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)

// verify keep attendees
func TestAddOriginalLink_Transform(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

addOriginalLink := AddOriginalLink{}

event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n",
}

assert.Equal(t, expectedEvent, event)
}

func TestAddOriginalLink_Transform_WithKeepDescription(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

keepDescription := KeepDescription{}
addOriginalLink := AddOriginalLink{}

sink, _ = keepDescription.Transform(source, sink)
event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\nbar",
}

assert.Equal(t, expectedEvent, event)
}

func TestAddOriginalLink_Transform_WithKeepDescriptionAndKeepMeetingLink(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
MeetingLink: "https://meetinglink.de",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

keepDescription := KeepDescription{}
keepMeetingLink := KeepMeetingLink{}
addOriginalLink := AddOriginalLink{}

sink, _ = keepDescription.Transform(source, sink)
sink, _ = keepMeetingLink.Transform(source, sink)
event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n" +
"original meeting link: https://meetinglink.de\n\n############\nbar",
}

assert.Equal(t, expectedEvent, event)
}
Loading