diff --git a/compose/rest/notification.go b/compose/rest/notification.go index ef2ea2081..c6983ed6f 100644 --- a/compose/rest/notification.go +++ b/compose/rest/notification.go @@ -8,19 +8,25 @@ import ( "github.com/cortezaproject/corteza-server/internal/mail" "github.com/pkg/errors" + gomail "gopkg.in/mail.v2" ) var _ = errors.Wrap type ( Notification struct { - notification service.NotificationService + notification notificationService } contentPayload struct { Plain string `json:"plain"` Html string `json:"html"` } + + notificationService interface { + SendEmail(*gomail.Message) error + AttachEmailRecipients(*gomail.Message, string, ...string) error + } ) func (Notification) New() *Notification { @@ -31,7 +37,7 @@ func (Notification) New() *Notification { // EmailSend assembles Email Message and pushes message to notification service func (ctrl *Notification) EmailSend(ctx context.Context, r *request.NotificationEmailSend) (interface{}, error) { - ntf := ctrl.notification.With(ctx) + ntf := ctrl.notification msg := mail.New() if err := ntf.AttachEmailRecipients(msg, "To", r.To...); err != nil { @@ -58,7 +64,7 @@ func (ctrl *Notification) EmailSend(ctx context.Context, r *request.Notification msg.SetHeader("Subject", r.Subject) - if err := ctrl.notification.With(ctx).SendEmail(msg); err != nil { + if err := ntf.SendEmail(msg); err != nil { return false, err } else { return true, nil diff --git a/compose/service/notification.go b/compose/service/notification.go index 7ba1ed46c..f813c711b 100644 --- a/compose/service/notification.go +++ b/compose/service/notification.go @@ -1,7 +1,6 @@ package service import ( - "context" "strings" "github.com/pkg/errors" @@ -13,28 +12,13 @@ import ( type ( notification struct { - ctx context.Context logger *zap.Logger } - - NotificationService interface { - With(ctx context.Context) NotificationService - - SendEmail(message *gomail.Message) error - AttachEmailRecipients(message *gomail.Message, field string, recipients ...string) error - } ) -func Notification() NotificationService { - return (¬ification{ - logger: DefaultLogger.Named("notification"), - }).With(context.Background()) -} - -func (svc notification) With(ctx context.Context) NotificationService { +func Notification() *notification { return ¬ification{ - ctx: ctx, - logger: svc.logger, + logger: DefaultLogger.Named("notification"), } } @@ -47,7 +31,7 @@ func (svc notification) SendEmail(message *gomail.Message) error { return mail.Send(message) } -// AttachEmailRecipients validates, resolves, formats andd attaches set of recipients to message +// AttachEmailRecipients validates, resolves, formats and attaches set of recipients to message // // Supports 3 input formats: // - diff --git a/compose/service/service.go b/compose/service/service.go index 956b5c6e2..6d9b85450 100644 --- a/compose/service/service.go +++ b/compose/service/service.go @@ -65,7 +65,7 @@ var ( DefaultChart ChartService DefaultPage PageService DefaultAttachment AttachmentService - DefaultNotification NotificationService + DefaultNotification *notification DefaultSystemUser *systemUser )