Fixed some validation weirdness when sending a test email. Fixes #739

pull/843/merge
Jordan Wright 2017-09-05 22:35:54 -05:00
parent ed217cd90e
commit 26d2ca7344
1 changed files with 6 additions and 5 deletions

View File

@ -683,6 +683,7 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
Logger.Printf("Error - Template %s does not exist", s.Template.Name) Logger.Printf("Error - Template %s does not exist", s.Template.Name)
JSONResponse(w, models.Response{Success: false, Message: models.ErrTemplateNotFound.Error()}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: models.ErrTemplateNotFound.Error()}, http.StatusBadRequest)
return
} else if err != nil { } else if err != nil {
Logger.Println(err) Logger.Println(err)
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
@ -693,15 +694,15 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
// If a complete sending profile is provided use it // If a complete sending profile is provided use it
if err := s.SMTP.Validate(); err != nil { if err := s.SMTP.Validate(); err != nil {
// Otherwise get the SMTP requested by name // Otherwise get the SMTP requested by name
s.SMTP, err = models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64)) smtp, lookupErr := models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64))
if err == gorm.ErrRecordNotFound { // If the Sending Profile doesn't exist, let's err on the side
Logger.Printf("Error - Sending profile %s does not exist", s.SMTP.Name) // of caution and assume that the validation failure was more important.
JSONResponse(w, models.Response{Success: false, Message: models.ErrSMTPNotFound.Error()}, http.StatusBadRequest) if lookupErr != nil {
} else if err != nil {
Logger.Println(err) Logger.Println(err)
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
return return
} }
s.SMTP = smtp
} }
// Send the test email // Send the test email