chore: move notifications models into notifications service (#61638)
This commit is contained in:
@@ -10,10 +10,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/events"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
tempuser "github.com/grafana/grafana/pkg/services/temp_user"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -21,11 +21,11 @@ import (
|
||||
)
|
||||
|
||||
type WebhookSender interface {
|
||||
SendWebhookSync(ctx context.Context, cmd *models.SendWebhookSync) error
|
||||
SendWebhookSync(ctx context.Context, cmd *SendWebhookSync) error
|
||||
}
|
||||
type EmailSender interface {
|
||||
SendEmailCommandHandlerSync(ctx context.Context, cmd *models.SendEmailCommandSync) error
|
||||
SendEmailCommandHandler(ctx context.Context, cmd *models.SendEmailCommand) error
|
||||
SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error
|
||||
SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error
|
||||
}
|
||||
type Service interface {
|
||||
WebhookSender
|
||||
@@ -130,7 +130,7 @@ func (ns *NotificationService) GetMailer() Mailer {
|
||||
return ns.mailer
|
||||
}
|
||||
|
||||
func (ns *NotificationService) SendWebhookSync(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
func (ns *NotificationService) SendWebhookSync(ctx context.Context, cmd *SendWebhookSync) error {
|
||||
return ns.sendWebRequestSync(ctx, &Webhook{
|
||||
Url: cmd.Url,
|
||||
User: cmd.User,
|
||||
@@ -148,8 +148,8 @@ func subjectTemplateFunc(obj map[string]interface{}, value string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (ns *NotificationService) SendEmailCommandHandlerSync(ctx context.Context, cmd *models.SendEmailCommandSync) error {
|
||||
message, err := ns.buildEmailMessage(&models.SendEmailCommand{
|
||||
func (ns *NotificationService) SendEmailCommandHandlerSync(ctx context.Context, cmd *SendEmailCommandSync) error {
|
||||
message, err := ns.buildEmailMessage(&SendEmailCommand{
|
||||
Data: cmd.Data,
|
||||
Info: cmd.Info,
|
||||
Template: cmd.Template,
|
||||
@@ -169,7 +169,7 @@ func (ns *NotificationService) SendEmailCommandHandlerSync(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
|
||||
func (ns *NotificationService) SendEmailCommandHandler(ctx context.Context, cmd *models.SendEmailCommand) error {
|
||||
func (ns *NotificationService) SendEmailCommandHandler(ctx context.Context, cmd *SendEmailCommand) error {
|
||||
message, err := ns.buildEmailMessage(cmd)
|
||||
|
||||
if err != nil {
|
||||
@@ -180,12 +180,12 @@ func (ns *NotificationService) SendEmailCommandHandler(ctx context.Context, cmd
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *models.SendResetPasswordEmailCommand) error {
|
||||
func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *SendResetPasswordEmailCommand) error {
|
||||
code, err := createUserEmailCode(ns.Cfg, cmd.User, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ns.SendEmailCommandHandler(ctx, &models.SendEmailCommand{
|
||||
return ns.SendEmailCommandHandler(ctx, &SendEmailCommand{
|
||||
To: []string{cmd.User.Email},
|
||||
Template: tmplResetPassword,
|
||||
Data: map[string]interface{}{
|
||||
@@ -197,10 +197,10 @@ func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *
|
||||
|
||||
type GetUserByLoginFunc = func(c context.Context, login string) (*user.User, error)
|
||||
|
||||
func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *models.ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) error {
|
||||
func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) error {
|
||||
login := getLoginForEmailCode(query.Code)
|
||||
if login == "" {
|
||||
return models.ErrInvalidEmailCode
|
||||
return ErrInvalidEmailCode
|
||||
}
|
||||
|
||||
user, err := userByLogin(ctx, login)
|
||||
@@ -213,7 +213,7 @@ func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, qu
|
||||
return err
|
||||
}
|
||||
if !validEmailCode {
|
||||
return models.ErrInvalidEmailCode
|
||||
return ErrInvalidEmailCode
|
||||
}
|
||||
|
||||
query.Result = user
|
||||
@@ -231,7 +231,7 @@ func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *ev
|
||||
return nil
|
||||
}
|
||||
|
||||
err := ns.SendEmailCommandHandler(ctx, &models.SendEmailCommand{
|
||||
err := ns.SendEmailCommandHandler(ctx, &SendEmailCommand{
|
||||
To: []string{evt.Email},
|
||||
Template: tmplSignUpStarted,
|
||||
Data: map[string]interface{}{
|
||||
@@ -254,7 +254,7 @@ func (ns *NotificationService) signUpCompletedHandler(ctx context.Context, evt *
|
||||
return nil
|
||||
}
|
||||
|
||||
return ns.SendEmailCommandHandler(ctx, &models.SendEmailCommand{
|
||||
return ns.SendEmailCommandHandler(ctx, &SendEmailCommand{
|
||||
To: []string{evt.Email},
|
||||
Template: tmplWelcomeOnSignUp,
|
||||
Data: map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user