Skip to content

Commit

Permalink
incorporate requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Sep 22, 2022
1 parent 7a8e1b8 commit e96ab9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
16 changes: 5 additions & 11 deletions services/notifications/pkg/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand All @@ -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").
Expand Down

0 comments on commit e96ab9f

Please sign in to comment.