Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Sep 16, 2022
1 parent 66f1dee commit a5c6c76
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
8 changes: 5 additions & 3 deletions services/notifications/pkg/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"path/filepath"
)

// go:embed templates/*.tmpl
var (
//go:embed templates
templatesFS embed.FS
)

// RenderEmailTemplate renders the email template for a new share
func RenderEmailTemplate(templateName string, templateVariables map[string]string, emailTemplatePath string) (string, error) {
var fs embed.FS
var err error
var tpl *template.Template
templateHasBeenFound := false
Expand All @@ -24,7 +26,7 @@ func RenderEmailTemplate(templateName string, templateVariables map[string]strin
}
if !templateHasBeenFound {
// template has not been found in the fs, or path has not been specified => use embed templates
tpl, err = template.ParseFS(fs, templateName)
tpl, err = template.ParseFS(templatesFS, filepath.Join("templates/", templateName))
if err != nil {
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ShareSharer}} has shared {{ShareFolder}} with you.
{{ .ShareSharer }} has shared {{ .ShareFolder }} with you.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{SpaceSharer}} has invited you to join {{SpaceName}}
{{ .SpaceSharer }} has invited you to join {{ .SpaceName }}
17 changes: 5 additions & 12 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s eventsNotifier) Run() error {

func (s eventsNotifier) handleSpaceCreated(e events.SpaceCreated) {
userResponse, err := s.gwClient.GetUser(context.Background(), &userv1beta1.GetUserRequest{
UserId: e.Executant,
UserId: e.Owner,
})
if err != nil || userResponse.Status.Code != rpcv1beta1.Code_CODE_OK {
s.logger.Error().
Expand Down Expand Up @@ -143,8 +143,9 @@ func (s eventsNotifier) handleSpaceCreated(e events.SpaceCreated) {

// old code
msg, err := email.RenderEmailTemplate("sharedSpace.email.tmpl", map[string]string{
// TODO: add additional fields here (like link etc.)
"SpaceSharer": "spacesharer",
"SpaceName": "spacename",
"SpaceName": md.Info.Space.Name,
}, s.emailTemplatePath)

if err != nil {
Expand Down Expand Up @@ -200,19 +201,10 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
}
ownerCtx = metadata.AppendToOutgoingContext(ownerCtx, ctxpkg.TokenHeader, authRes.Token)

resourceID, err := storagespace.ParseID(e.ItemID.OpaqueId)
if err != nil {
s.logger.Error().
Err(err).
Str("event", "ShareCreated").
Str("itemid", e.ItemID.OpaqueId).
Msg("could not parse resourceid from ItemID ")
return
}
// TODO: maybe cache this stat to reduce storage iops
md, err := s.gwClient.Stat(ownerCtx, &providerv1beta1.StatRequest{
Ref: &providerv1beta1.Reference{
ResourceId: &resourceID,
ResourceId: e.ItemID,
},
FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"name"}},
})
Expand All @@ -237,6 +229,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
}

msg, err := email.RenderEmailTemplate("shareCreated.email.tmpl", map[string]string{
// TODO: add additional fields here (like link etc.)
"ShareSharer": userResponse.User.DisplayName,
"ShareFolder": md.Info.Name,
}, s.emailTemplatePath)
Expand Down

0 comments on commit a5c6c76

Please sign in to comment.