Selaa lähdekoodia

Final work password reset email, Closes #1456

Torkel Ödegaard 10 vuotta sitten
vanhempi
commit
bb2d810709

+ 1 - 0
conf/defaults.ini

@@ -188,6 +188,7 @@ from_address = admin@grafana.localhost
 
 [emails]
 welcome_email_on_sign_up = false
+templates_pattern = emails/*.html
 
 #################################### Logging ##########################
 [log]

+ 1 - 1
pkg/services/notifications/notifications.go

@@ -32,7 +32,7 @@ func Init() error {
 		"Subject": subjectTemplateFunc,
 	})
 
-	templatePattern := filepath.Join(setting.StaticRootPath, "emails/*.html")
+	templatePattern := filepath.Join(setting.StaticRootPath, setting.Smtp.TemplatesPattern)
 	_, err := mailTemplates.ParseGlob(templatePattern)
 	if err != nil {
 		return err

+ 4 - 1
pkg/services/notifications/notifications_test.go

@@ -15,6 +15,8 @@ func TestNotifications(t *testing.T) {
 		bus.ClearBusHandlers()
 
 		setting.StaticRootPath = "../../../public/"
+		setting.Smtp.Enabled = true
+		setting.Smtp.TemplatesPattern = "emails/*.html"
 		setting.Smtp.FromAddress = "from@address.com"
 
 		err := Init()
@@ -26,7 +28,8 @@ func TestNotifications(t *testing.T) {
 		}
 
 		Convey("When sending reset email password", func() {
-			sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
+			err := sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
+			So(err, ShouldBeNil)
 			So(sentMsg.Body, ShouldContainSubstring, "body")
 			So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password")
 			So(sentMsg.Body, ShouldNotContainSubstring, "Subject")

+ 2 - 0
pkg/setting/setting_smtp.go

@@ -11,6 +11,7 @@ type SmtpSettings struct {
 	SkipVerify  bool
 
 	SendWelcomeEmailOnSignUp bool
+	TemplatesPattern         string
 }
 
 func readSmtpSettings() {
@@ -26,4 +27,5 @@ func readSmtpSettings() {
 
 	emails := Cfg.Section("emails")
 	Smtp.SendWelcomeEmailOnSignUp = emails.Key("welcome_email_on_sign_up").MustBool(false)
+	Smtp.TemplatesPattern = emails.Key("templates_pattern").MustString("emails/*.html")
 }