From e96ab9f9c812b4d1d7f1991499e07af939a6e0e6 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 22 Sep 2022 09:37:54 +0200 Subject: [PATCH] incorporate requested changes Signed-off-by: Christian Richter --- services/notifications/pkg/email/email.go | 16 +++++----------- services/notifications/pkg/service/service.go | 10 +++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/services/notifications/pkg/email/email.go b/services/notifications/pkg/email/email.go index c0709b9ea17..d3302ccdf74 100644 --- a/services/notifications/pkg/email/email.go +++ b/services/notifications/pkg/email/email.go @@ -16,23 +16,17 @@ var ( func RenderEmailTemplate(templateName string, templateVariables map[string]string, emailTemplatePath string) (string, error) { var err error var tpl *template.Template - templateHasBeenFound := false - if emailTemplatePath != "" { - // try to lookup the files in the filesystem - tpl, err = template.ParseFiles(filepath.Join(emailTemplatePath, templateName)) - if err == nil { - templateHasBeenFound = true - } - } - if !templateHasBeenFound { + // try to lookup the files in the filesystem + tpl, err = template.ParseFiles(filepath.Join(emailTemplatePath, templateName)) + if err != nil { // template has not been found in the fs, or path has not been specified => use embed templates tpl, err = template.ParseFS(templatesFS, filepath.Join("templates/", templateName)) if err != nil { return "", err } } - writer := bytes.NewBufferString("") - err = tpl.Execute(writer, templateVariables) + var writer bytes.Buffer + err = tpl.Execute(&writer, templateVariables) if err != nil { return "", err } diff --git a/services/notifications/pkg/service/service.go b/services/notifications/pkg/service/service.go index eb7b324d027..d2f35e11774 100644 --- a/services/notifications/pkg/service/service.go +++ b/services/notifications/pkg/service/service.go @@ -86,7 +86,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) { } granteeUserResponse, err := s.gwClient.GetUser(context.Background(), &userv1beta1.GetUserRequest{ - UserId: e.Creator, + UserId: e.GranteeUserID, }) if err != nil || sharerUserResponse.Status.Code != rpcv1beta1.Code_CODE_OK { s.logger.Error(). @@ -102,7 +102,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) { ClientId: "userid:" + e.Executant.OpaqueId, ClientSecret: s.machineAuthAPIKey, }) - if err != nil || authRes.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK { + if err != nil { s.logger.Error(). Err(err). Str("event", "SpaceCreated"). @@ -137,7 +137,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) { //FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"space.name"}}, }) - if err != nil || md.Status.Code != rpcv1beta1.Code_CODE_OK { + if err != nil { s.logger.Error(). Err(err). Str("event", "ShareCreated"). @@ -225,7 +225,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) { ClientId: "userid:" + e.Sharer.OpaqueId, ClientSecret: s.machineAuthAPIKey, }) - if err != nil || authRes.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK { + if err != nil { s.logger.Error(). Err(err). Str("event", "ShareCreated"). @@ -250,7 +250,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) { FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"name"}}, }) - if err != nil || md.Status.Code != rpcv1beta1.Code_CODE_OK { + if err != nil { s.logger.Error(). Err(err). Str("event", "ShareCreated").