diff --git a/pkg/provision/migrations_202103_templates.go b/pkg/provision/migrations_202103_templates.go index f5e04e9c6..7f077ca41 100644 --- a/pkg/provision/migrations_202103_templates.go +++ b/pkg/provision/migrations_202103_templates.go @@ -40,12 +40,12 @@ func migrateEmailTemplates(ctx context.Context, log *zap.Logger, s store.Storer) }, "auth.mail.email-confirmation.subject.en": { Type: "text/plain", - Handle: "auth_email_confirmation_subject", + Handle: "auth_email_confirm_subject", Meta: types.TemplateMeta{Short: "Password reset subject"}, }, "auth.mail.email-confirmation.body.en": { Type: "text/html", - Handle: "auth_email_confirmation_body", + Handle: "auth_email_confirm_body", Meta: types.TemplateMeta{Short: "Password reset content"}, }, "auth.mail.password-reset.subject.en": { diff --git a/system/service/auth_notification.go b/system/service/auth_notification.go index 8a17f3049..f0d35dac9 100644 --- a/system/service/auth_notification.go +++ b/system/service/auth_notification.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/url" + intAuth "github.com/cortezaproject/corteza-server/pkg/auth" "github.com/cortezaproject/corteza-server/pkg/logger" "github.com/cortezaproject/corteza-server/pkg/mail" "github.com/cortezaproject/corteza-server/pkg/options" @@ -82,17 +83,21 @@ func (svc authNotification) send(ctx context.Context, name, sendTo string, paylo tmp []byte ntf = svc.newMail() hdl string + + // context with service user + // we need this for retrieving & rendering email templates + suCtx = intAuth.SetIdentityToContext(ctx, intAuth.ServiceUser()) ) // Fetch parts hdl = name + "_subject" - st, err := svc.ts.FindByHandle(ctx, hdl) + st, err := svc.ts.FindByHandle(suCtx, hdl) if err != nil { return fmt.Errorf("cannot generate auth email with template %s: %w", hdl, err) } hdl = name + "_content" - ct, err := svc.ts.FindByHandle(ctx, hdl) + ct, err := svc.ts.FindByHandle(suCtx, hdl) if err != nil { return fmt.Errorf("cannot generate auth email with template %s: %w", hdl, err) } @@ -105,12 +110,12 @@ func (svc authNotification) send(ctx context.Context, name, sendTo string, paylo payload["EmailAddress"] = sendTo // Render document - subject, err := svc.ts.Render(ctx, st.ID, "text/plain", payload, nil) + subject, err := svc.ts.Render(suCtx, st.ID, "text/plain", payload, nil) if err != nil { return err } - content, err := svc.ts.Render(ctx, ct.ID, "text/plain", payload, nil) + content, err := svc.ts.Render(suCtx, ct.ID, "text/plain", payload, nil) if err != nil { return err }