changeset 5370:566c8063223b extented-report

Allow test mail sinding for waterway users, too.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 24 Jun 2021 13:12:59 +0200
parents 4d126cf58fbc
children 0de64b3017ac
files pkg/controllers/user.go
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/user.go	Thu Jun 24 10:53:44 2021 +0200
+++ b/pkg/controllers/user.go	Thu Jun 24 13:12:59 2021 +0200
@@ -94,13 +94,20 @@
 	testWWAdminNotifyMailTmpl = template.Must(
 		template.New("waterwayadmin").Parse(`Dear {{ .User }},
 
-this is a test email for the Gemma System Imports notification service.  You
+this is a test email for the Gemma System Mail notification service.  You
 recieved this mail, because a System Administrator triggered the test mail
 sending function at {{ .Timestamp }}.
 
 When the status of an data import managed by you changes an automated mail will
 be send to the address: {{ .Email }} with details on the new import status
-(inkluding import errors) and details on the concerned import.`))
+(including import errors) and details on the concerned import.`))
+
+	testWWUserNotifyMailTmpl = template.Must(
+		template.New("waterwayuser").Parse(`Dear {{ .User }},
+
+this is a test email for the Gemma System Mail notification service.  You
+recieved this mail, because a System Administrator triggered the test mail
+sending function at {{ .Timestamp }}.`))
 )
 
 func deleteUser(req *http.Request) (jr mw.JSONResult, err error) {
@@ -550,19 +557,18 @@
 	}
 
 	var bodyTmpl *template.Template
-	if userData.Role == "sys_admin" {
+	switch userData.Role {
+	case "sys_admin":
 		subject = "Gemma: Sysadmin Notification TEST"
 		bodyTmpl = testSysadminNotifyMailTmpl
-	} else if userData.Role == "waterway_admin" {
+	case "waterway_admin":
 		subject = "Gemma: Waterway Admin Notification TEST"
 		bodyTmpl = testWWAdminNotifyMailTmpl
-	} else {
-		err = mw.JSONError{
-			Code:    http.StatusBadRequest,
-			Message: "Test mails can only be generated for admin roles.",
-		}
-		return
+	default:
+		subject = "Gemma: Waterway User Notification TEST"
+		bodyTmpl = testWWUserNotifyMailTmpl
 	}
+
 	var buf bytes.Buffer
 	if err := bodyTmpl.Execute(&buf, &tmplVars); err != nil {
 		log.Printf("error: %v\n", err)