diff --git a/changelog/unreleased/add-subject-tempalting.md b/changelog/unreleased/add-subject-tempalting.md new file mode 100644 index 000000000..e33b34e9d --- /dev/null +++ b/changelog/unreleased/add-subject-tempalting.md @@ -0,0 +1,5 @@ +Enhancement: We added e-mail subject templating + +We have added e-mail subject templating. + +https://github.com/owncloud/ocis/pull/4799 \ No newline at end of file diff --git a/services/notifications/pkg/email/templates/shareCreated.email.tmpl b/services/notifications/pkg/email/templates/shares/shareCreated.email.body.tmpl similarity index 100% rename from services/notifications/pkg/email/templates/shareCreated.email.tmpl rename to services/notifications/pkg/email/templates/shares/shareCreated.email.body.tmpl diff --git a/services/notifications/pkg/email/templates/shares/shareCreated.email.subject.tmpl b/services/notifications/pkg/email/templates/shares/shareCreated.email.subject.tmpl new file mode 100644 index 000000000..09dccb9d8 --- /dev/null +++ b/services/notifications/pkg/email/templates/shares/shareCreated.email.subject.tmpl @@ -0,0 +1 @@ +{{ .ShareSharer }} shared '{{ .ShareFolder }}' with you \ No newline at end of file diff --git a/services/notifications/pkg/email/templates/sharedSpace.email.tmpl b/services/notifications/pkg/email/templates/spaces/sharedSpace.email.body.tmpl similarity index 100% rename from services/notifications/pkg/email/templates/sharedSpace.email.tmpl rename to services/notifications/pkg/email/templates/spaces/sharedSpace.email.body.tmpl diff --git a/services/notifications/pkg/email/templates/spaces/sharedSpace.email.subject.tmpl b/services/notifications/pkg/email/templates/spaces/sharedSpace.email.subject.tmpl new file mode 100644 index 000000000..e65e04292 --- /dev/null +++ b/services/notifications/pkg/email/templates/spaces/sharedSpace.email.subject.tmpl @@ -0,0 +1 @@ +{{ .SpaceSharer }} invited you to join {{ .SpaceName }} \ No newline at end of file diff --git a/services/notifications/pkg/service/service.go b/services/notifications/pkg/service/service.go index c16b48ee2..94e74c9b4 100644 --- a/services/notifications/pkg/service/service.go +++ b/services/notifications/pkg/service/service.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "net/url" "os" "os/signal" @@ -200,7 +199,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) { } sharerDisplayName := sharerUserResponse.GetUser().DisplayName - msg, err := email.RenderEmailTemplate("sharedSpace.email.tmpl", map[string]string{ + msg, err := email.RenderEmailTemplate("spaces/sharedSpace.email.body.tmpl", map[string]string{ "SpaceGrantee": spaceGrantee, "SpaceSharer": sharerDisplayName, "SpaceName": md.GetInfo().GetSpace().Name, @@ -211,10 +210,21 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) { s.logger.Error(). Err(err). Str("event", "SpaceCreated"). - Msg("Could not render E-Mail template for spaces") + Msg("Could not render E-Mail body template for spaces") + } + + emailSubject, err := email.RenderEmailTemplate("spaces/sharedSpace.email.subject.tmpl", map[string]string{ + "SpaceSharer": sharerDisplayName, + "SpaceName": md.GetInfo().GetSpace().Name, + }, s.emailTemplatePath) + + if err != nil { + s.logger.Error(). + Err(err). + Str("event", "SpaceCreated"). + Msg("Could not render E-Mail subject template for spaces") } - emailSubject := fmt.Sprintf("%s invited you to join %s", sharerUserResponse.GetUser().DisplayName, md.GetInfo().GetSpace().Name) if e.GranteeUserID != nil { err = s.channel.SendMessage(ownerCtx, []string{e.GranteeUserID.OpaqueId}, msg, emailSubject, sharerDisplayName) } else if e.GranteeGroupID != nil { @@ -338,7 +348,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) { } sharerDisplayName := sharerUserResponse.GetUser().DisplayName - msg, err := email.RenderEmailTemplate("shareCreated.email.tmpl", map[string]string{ + msg, err := email.RenderEmailTemplate("shares/shareCreated.email.body.tmpl", map[string]string{ "ShareGrantee": shareGrantee, "ShareSharer": sharerDisplayName, "ShareFolder": md.GetInfo().Name, @@ -349,10 +359,21 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) { s.logger.Error(). Err(err). Str("event", "ShareCreated"). - Msg("Could not render E-Mail template for shares") + Msg("Could not render E-Mail body template for shares") + } + + emailSubject, err := email.RenderEmailTemplate("shares/shareCreated.email.subject.tmpl", map[string]string{ + "ShareSharer": sharerDisplayName, + "ShareFolder": md.GetInfo().Name, + }, s.emailTemplatePath) + + if err != nil { + s.logger.Error(). + Err(err). + Str("event", "SpaceCreated"). + Msg("Could not render E-Mail subject template for shares") } - emailSubject := fmt.Sprintf("%s shared '%s' with you", sharerUserResponse.GetUser().DisplayName, md.GetInfo().Name) if e.GranteeUserID != nil { err = s.channel.SendMessage(ownerCtx, []string{e.GranteeUserID.OpaqueId}, msg, emailSubject, sharerDisplayName) } else if e.GranteeGroupID != nil {