管理员可在周报页先发一封测试邮件验证邮箱配置;测试不写入发送记录、不改变确认状态,也不会把该周标记为已发送。
This commit is contained in:
@@ -16,6 +16,7 @@ type weeklyMailStore interface {
|
||||
Unconfirm(context.Context, string) error
|
||||
ReadConfirmation(context.Context, string) (*qawemail.Confirmation, error)
|
||||
Sends(context.Context, string) ([]qawemail.Send, error)
|
||||
TestSend(context.Context, string) (string, error)
|
||||
SendDue(context.Context, time.Time) (qawemail.DueResult, error)
|
||||
}
|
||||
|
||||
@@ -134,3 +135,40 @@ func qaWeeklyMailSends(w http.ResponseWriter, r *http.Request, c Config) {
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]any{"sends": sends}})
|
||||
}
|
||||
|
||||
func qaWeeklyMailTest(w http.ResponseWriter, r *http.Request, c Config) {
|
||||
if !authorizeQAOps(w, r) || !authorizeQAIntent(w, r, "qa-weekly-mail") {
|
||||
return
|
||||
}
|
||||
identity, ok := sessionFrom(r.Context())
|
||||
if !ok || identity.Role != "admin" {
|
||||
writeJSON(w, http.StatusForbidden, map[string]string{"error": "仅管理员可发送测试邮件"})
|
||||
return
|
||||
}
|
||||
store, found := c.QAWeeklyMail.(weeklyMailStore)
|
||||
if !found {
|
||||
weeklyMailError(w, qawemail.ErrUnavailable)
|
||||
return
|
||||
}
|
||||
var request struct {
|
||||
Week string `json:"week"`
|
||||
}
|
||||
if decodeQualityJSON(w, r, &request) != nil {
|
||||
weeklyMailError(w, qawemail.ErrInvalid)
|
||||
return
|
||||
}
|
||||
messageID, err := store.TestSend(r.Context(), request.Week)
|
||||
if err != nil {
|
||||
if errors.Is(err, qawemail.ErrInvalid) {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "请先保存该周周报正文,并确认已配置服务器、发件人、收件人与授权码"})
|
||||
return
|
||||
}
|
||||
reason := err.Error()
|
||||
if len(reason) > 300 {
|
||||
reason = reason[:300]
|
||||
}
|
||||
writeJSON(w, http.StatusBadGateway, map[string]string{"error": "测试发送失败:" + reason})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"data": map[string]any{"sent": true, "week": request.Week, "message_id": messageID}})
|
||||
}
|
||||
|
||||
@@ -210,6 +210,7 @@ func NewHandler(config Config) (http.Handler, error) {
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/master/weekly-mail/confirmations/{week}", func(w http.ResponseWriter, r *http.Request) { qaWeeklyMailConfirm(w, r, config) })
|
||||
mux.HandleFunc("DELETE /api/v1/qa-ops/master/weekly-mail/confirmations/{week}", func(w http.ResponseWriter, r *http.Request) { qaWeeklyMailConfirm(w, r, config) })
|
||||
mux.HandleFunc("GET /api/v1/qa-ops/master/weekly-mail/sends", func(w http.ResponseWriter, r *http.Request) { qaWeeklyMailSends(w, r, config) })
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/master/weekly-mail/test", func(w http.ResponseWriter, r *http.Request) { qaWeeklyMailTest(w, r, config) })
|
||||
mux.HandleFunc("GET /api/v1/qa-ops/master/field-options", func(w http.ResponseWriter, r *http.Request) { qaMasterFieldOptions(w, r, config) })
|
||||
mux.HandleFunc("POST /api/v1/qa-ops/master/records/{id}/fields", func(w http.ResponseWriter, r *http.Request) { qaMasterFieldPatch(w, r, config) })
|
||||
mux.HandleFunc("GET /api/v1/qa-ops/master/records", func(w http.ResponseWriter, r *http.Request) { withQAMaster(w, r, config, listQAOpsRecords) })
|
||||
|
||||
Reference in New Issue
Block a user