mirror of https://gitee.com/answerdev/answer.git
fix(email): fix the old email config format
This commit is contained in:
parent
432bf21c98
commit
4a0fa27a34
|
@ -261,6 +261,9 @@ backend:
|
|||
upload:
|
||||
unsupported_file_format:
|
||||
other: Unsupported file format.
|
||||
site_info:
|
||||
config_not_found:
|
||||
other: Site config not found.
|
||||
reason:
|
||||
spam:
|
||||
name:
|
||||
|
|
|
@ -61,7 +61,7 @@ const (
|
|||
DatabaseConnectionFailed = "error.database.connection_failed"
|
||||
InstallCreateTableFailed = "error.database.create_table_failed"
|
||||
InstallConfigFailed = "error.install.create_config_failed"
|
||||
SiteInfoNotFound = "error.site_info.not_found"
|
||||
SiteInfoConfigNotFound = "error.site_info.config_not_found"
|
||||
UploadFileSourceUnsupported = "error.upload.source_unsupported"
|
||||
UploadFileUnsupportedFileFormat = "error.upload.unsupported_file_format"
|
||||
RecommendTagNotExist = "error.tag.recommend_tag_not_found"
|
||||
|
|
|
@ -80,8 +80,8 @@ func (cr configRepo) GetConfigByKey(ctx context.Context, key string) (c *entity.
|
|||
|
||||
func (cr configRepo) UpdateConfig(ctx context.Context, key string, value string) (err error) {
|
||||
// check if key exists
|
||||
cf := &entity.Config{}
|
||||
exist, err := cr.data.DB.Context(ctx).Get(cf)
|
||||
oldConfig := &entity.Config{}
|
||||
exist, err := cr.data.DB.Context(ctx).Get(oldConfig)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
|
@ -90,19 +90,20 @@ func (cr configRepo) UpdateConfig(ctx context.Context, key string, value string)
|
|||
}
|
||||
|
||||
// update database
|
||||
_, err = cr.data.DB.Context(ctx).ID(cf.ID).Update(&entity.Config{Value: value})
|
||||
_, err = cr.data.DB.Context(ctx).ID(oldConfig.ID).Update(&entity.Config{Value: value})
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
}
|
||||
|
||||
cacheVal := cf.JsonString()
|
||||
oldConfig.Value = value
|
||||
cacheVal := oldConfig.JsonString()
|
||||
// update cache
|
||||
if err := cr.data.Cache.SetString(ctx,
|
||||
constant.ConfigKEY2ContentCacheKeyPrefix+key, cacheVal, -1); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if err := cr.data.Cache.SetString(ctx,
|
||||
fmt.Sprintf("%s%d", constant.ConfigID2KEYCacheKeyPrefix, cf.ID), cacheVal, -1); err != nil {
|
||||
fmt.Sprintf("%s%d", constant.ConfigID2KEYCacheKeyPrefix, oldConfig.ID), cacheVal, -1); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
return
|
||||
|
|
|
@ -54,19 +54,6 @@ type EmailConfig struct {
|
|||
SMTPUsername string `json:"smtp_username"`
|
||||
SMTPPassword string `json:"smtp_password"`
|
||||
SMTPAuthentication bool `json:"smtp_authentication"`
|
||||
|
||||
RegisterTitle string `json:"register_title"`
|
||||
RegisterBody string `json:"register_body"`
|
||||
PassResetTitle string `json:"pass_reset_title"`
|
||||
PassResetBody string `json:"pass_reset_body"`
|
||||
ChangeTitle string `json:"change_title"`
|
||||
ChangeBody string `json:"change_body"`
|
||||
TestTitle string `json:"test_title"`
|
||||
TestBody string `json:"test_body"`
|
||||
NewAnswerTitle string `json:"new_answer_title"`
|
||||
NewAnswerBody string `json:"new_answer_body"`
|
||||
NewCommentTitle string `json:"new_comment_title"`
|
||||
NewCommentBody string `json:"new_comment_body"`
|
||||
}
|
||||
|
||||
func (e *EmailConfig) IsSSL() bool {
|
||||
|
@ -306,7 +293,8 @@ func (es *EmailService) GetEmailConfig(ctx context.Context) (ec *EmailConfig, er
|
|||
ec = &EmailConfig{}
|
||||
err = json.Unmarshal([]byte(emailConf), ec)
|
||||
if err != nil {
|
||||
return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
log.Errorf("old email config format is invalid, you need to update smtp config: %v", err)
|
||||
return nil, errors.BadRequest(reason.SiteInfoConfigNotFound)
|
||||
}
|
||||
return ec, nil
|
||||
}
|
||||
|
|
|
@ -227,9 +227,7 @@ func (s *SiteInfoService) SaveSiteUsers(ctx context.Context, req *schema.SiteUse
|
|||
}
|
||||
|
||||
// GetSMTPConfig get smtp config
|
||||
func (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (
|
||||
resp *schema.GetSMTPConfigResp, err error,
|
||||
) {
|
||||
func (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (resp *schema.GetSMTPConfigResp, err error) {
|
||||
emailConfig, err := s.emailService.GetEmailConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -241,13 +239,10 @@ func (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (
|
|||
|
||||
// UpdateSMTPConfig get smtp config
|
||||
func (s *SiteInfoService) UpdateSMTPConfig(ctx context.Context, req *schema.UpdateSMTPConfigReq) (err error) {
|
||||
oldEmailConfig, err := s.emailService.GetEmailConfig(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = copier.Copy(oldEmailConfig, req)
|
||||
ec := &export.EmailConfig{}
|
||||
_ = copier.Copy(ec, req)
|
||||
|
||||
err = s.emailService.SetEmailConfig(ctx, oldEmailConfig)
|
||||
err = s.emailService.SetEmailConfig(ctx, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -258,7 +253,7 @@ func (s *SiteInfoService) UpdateSMTPConfig(ctx context.Context, req *schema.Upda
|
|||
}
|
||||
go s.emailService.SendAndSaveCode(ctx, req.TestEmailRecipient, title, body, "", "")
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SiteInfoService) GetSeo(ctx context.Context) (resp *schema.SiteSeoReq, err error) {
|
||||
|
|
Loading…
Reference in New Issue