comparison pkg/controllers/user.go @ 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 95dafb72a288
children 5d6aa584b4fb
comparison
equal deleted inserted replaced
5369:4d126cf58fbc 5370:566c8063223b
92 the address: {{ .Email }} with details on the error condition.`)) 92 the address: {{ .Email }} with details on the error condition.`))
93 93
94 testWWAdminNotifyMailTmpl = template.Must( 94 testWWAdminNotifyMailTmpl = template.Must(
95 template.New("waterwayadmin").Parse(`Dear {{ .User }}, 95 template.New("waterwayadmin").Parse(`Dear {{ .User }},
96 96
97 this is a test email for the Gemma System Imports notification service. You 97 this is a test email for the Gemma System Mail notification service. You
98 recieved this mail, because a System Administrator triggered the test mail 98 recieved this mail, because a System Administrator triggered the test mail
99 sending function at {{ .Timestamp }}. 99 sending function at {{ .Timestamp }}.
100 100
101 When the status of an data import managed by you changes an automated mail will 101 When the status of an data import managed by you changes an automated mail will
102 be send to the address: {{ .Email }} with details on the new import status 102 be send to the address: {{ .Email }} with details on the new import status
103 (inkluding import errors) and details on the concerned import.`)) 103 (including import errors) and details on the concerned import.`))
104
105 testWWUserNotifyMailTmpl = template.Must(
106 template.New("waterwayuser").Parse(`Dear {{ .User }},
107
108 this is a test email for the Gemma System Mail notification service. You
109 recieved this mail, because a System Administrator triggered the test mail
110 sending function at {{ .Timestamp }}.`))
104 ) 111 )
105 112
106 func deleteUser(req *http.Request) (jr mw.JSONResult, err error) { 113 func deleteUser(req *http.Request) (jr mw.JSONResult, err error) {
107 114
108 user := mux.Vars(req)["user"] 115 user := mux.Vars(req)["user"]
548 Timestamp: time.Now().Format("2006-01-02 15:04:05"), 555 Timestamp: time.Now().Format("2006-01-02 15:04:05"),
549 Email: string(userData.Email), 556 Email: string(userData.Email),
550 } 557 }
551 558
552 var bodyTmpl *template.Template 559 var bodyTmpl *template.Template
553 if userData.Role == "sys_admin" { 560 switch userData.Role {
561 case "sys_admin":
554 subject = "Gemma: Sysadmin Notification TEST" 562 subject = "Gemma: Sysadmin Notification TEST"
555 bodyTmpl = testSysadminNotifyMailTmpl 563 bodyTmpl = testSysadminNotifyMailTmpl
556 } else if userData.Role == "waterway_admin" { 564 case "waterway_admin":
557 subject = "Gemma: Waterway Admin Notification TEST" 565 subject = "Gemma: Waterway Admin Notification TEST"
558 bodyTmpl = testWWAdminNotifyMailTmpl 566 bodyTmpl = testWWAdminNotifyMailTmpl
559 } else { 567 default:
560 err = mw.JSONError{ 568 subject = "Gemma: Waterway User Notification TEST"
561 Code: http.StatusBadRequest, 569 bodyTmpl = testWWUserNotifyMailTmpl
562 Message: "Test mails can only be generated for admin roles.", 570 }
563 } 571
564 return
565 }
566 var buf bytes.Buffer 572 var buf bytes.Buffer
567 if err := bodyTmpl.Execute(&buf, &tmplVars); err != nil { 573 if err := bodyTmpl.Execute(&buf, &tmplVars); err != nil {
568 log.Printf("error: %v\n", err) 574 log.Printf("error: %v\n", err)
569 } 575 }
570 576