You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/07/25 02:10:51 UTC
(incubator-answer) branch feat/1.3.6/user created (now 8cb5dd99)
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a change to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
at 8cb5dd99 Merge branch 'dev' into feat/1.3.6/user
This branch includes the following new commits:
new f014602e feat(user): change the hash way of gravatar
new 2820efc4 feat(user): ensure that only one link is active at a time
new 4c43e85d feat(email): add mask for email configˆ
new 8f30a153 fix(question): update answer count after reviewing
new 8cb5dd99 Merge branch 'dev' into feat/1.3.6/user
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-answer) 01/05: feat(user): change the hash way of gravatar
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit f014602ec7a5303a84b9a80458fca0589c7128bb
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jul 22 11:40:04 2024 +0800
feat(user): change the hash way of gravatar
---
pkg/gravatar/gravatar.go | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/pkg/gravatar/gravatar.go b/pkg/gravatar/gravatar.go
index 40cc7fd5..9c79b387 100644
--- a/pkg/gravatar/gravatar.go
+++ b/pkg/gravatar/gravatar.go
@@ -20,17 +20,18 @@
package gravatar
import (
- "crypto/md5"
+ "crypto/sha256"
"encoding/hex"
"fmt"
"net/url"
+ "strings"
)
// GetAvatarURL get avatar url from gravatar by email
func GetAvatarURL(baseURL, email string) string {
- h := md5.New()
- h.Write([]byte(email))
- return baseURL + hex.EncodeToString(h.Sum(nil))
+ hasher := sha256.Sum256([]byte(strings.TrimSpace(email)))
+ hash := hex.EncodeToString(hasher[:])
+ return baseURL + hash
}
// Resize resize avatar by pixel
(incubator-answer) 03/05: feat(email): add mask for email configˆ
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 4c43e85d89095e239ce6a2250514be1b177f211e
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Wed Jul 24 10:57:11 2024 +0800
feat(email): add mask for email configˆ
---
internal/base/constant/site_info.go | 4 ++++
internal/service/export/email_service.go | 4 ++--
internal/service/siteinfo/siteinfo_service.go | 11 +++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/internal/base/constant/site_info.go b/internal/base/constant/site_info.go
index de6f4183..0509c359 100644
--- a/internal/base/constant/site_info.go
+++ b/internal/base/constant/site_info.go
@@ -44,3 +44,7 @@ const (
ColorSchemeDark = "dark"
ColorSchemeSystem = "system"
)
+
+const (
+ EmailConfigKey = "email.config"
+)
diff --git a/internal/service/export/email_service.go b/internal/service/export/email_service.go
index ae5d337a..1ed1b784 100644
--- a/internal/service/export/email_service.go
+++ b/internal/service/export/email_service.go
@@ -328,7 +328,7 @@ func (es *EmailService) NewQuestionTemplate(ctx context.Context, raw *schema.New
}
func (es *EmailService) GetEmailConfig(ctx context.Context) (ec *EmailConfig, err error) {
- emailConf, err := es.configService.GetStringValue(ctx, "email.config")
+ emailConf, err := es.configService.GetStringValue(ctx, constant.EmailConfigKey)
if err != nil {
return nil, err
}
@@ -344,5 +344,5 @@ func (es *EmailService) GetEmailConfig(ctx context.Context) (ec *EmailConfig, er
// SetEmailConfig set email config
func (es *EmailService) SetEmailConfig(ctx context.Context, ec *EmailConfig) (err error) {
data, _ := json.Marshal(ec)
- return es.configService.UpdateConfig(ctx, "email.config", string(data))
+ return es.configService.UpdateConfig(ctx, constant.EmailConfigKey, string(data))
}
diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index 74027ec2..e1998efb 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -23,6 +23,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "strings"
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/handler"
@@ -257,14 +258,24 @@ func (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (resp *schema.GetSM
}
resp = &schema.GetSMTPConfigResp{}
_ = copier.Copy(resp, emailConfig)
+ resp.SMTPPassword = strings.Repeat("*", len(resp.SMTPPassword))
return resp, nil
}
// UpdateSMTPConfig get smtp config
func (s *SiteInfoService) UpdateSMTPConfig(ctx context.Context, req *schema.UpdateSMTPConfigReq) (err error) {
+ emailConfig, err := s.emailService.GetEmailConfig(ctx)
+ if err != nil {
+ return err
+ }
+
ec := &export.EmailConfig{}
_ = copier.Copy(ec, req)
+ if len(ec.SMTPPassword) > 0 && ec.SMTPPassword == strings.Repeat("*", len(ec.SMTPPassword)) {
+ ec.SMTPPassword = emailConfig.SMTPPassword
+ }
+
err = s.emailService.SetEmailConfig(ctx, ec)
if err != nil {
return err
(incubator-answer) 02/05: feat(user): ensure that only one link is active at a time
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 2820efc454f5808974dce0aa99aac106be3f727b
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jul 22 17:34:51 2024 +0800
feat(user): ensure that only one link is active at a time
---
internal/base/constant/cache_key.go | 3 ++
internal/repo/export/email_repo.go | 43 ++++++++++++++++++++--
internal/schema/email_template.go | 2 +
internal/service/content/user_service.go | 8 ++--
internal/service/export/email_service.go | 20 +++++-----
.../notification/invite_answer_notification.go | 7 ++--
.../notification/new_answer_notification.go | 7 ++--
.../notification/new_comment_notification.go | 7 ++--
.../notification/new_question_notification.go | 3 +-
internal/service/siteinfo/siteinfo_service.go | 2 +-
internal/service/user_admin/user_backyard.go | 17 ++++-----
.../user_external_login_service.go | 2 +-
12 files changed, 83 insertions(+), 38 deletions(-)
diff --git a/internal/base/constant/cache_key.go b/internal/base/constant/cache_key.go
index a3558aae..4135b53c 100644
--- a/internal/base/constant/cache_key.go
+++ b/internal/base/constant/cache_key.go
@@ -32,6 +32,9 @@ const (
AdminTokenCacheKey = "answer:admin:token:"
AdminTokenCacheTime = 7 * 24 * time.Hour
UserTokenMappingCacheKey = "answer:user-token:mapping:"
+ UserEmailCodeCacheKey = "answer:user:email-code:"
+ UserEmailCodeCacheTime = 10 * time.Minute
+ UserLatestEmailCodeCacheKey = "answer:user-id:email-code:"
SiteInfoCacheKey = "answer:site-info:"
SiteInfoCacheTime = 1 * time.Hour
ConfigID2KEYCacheKeyPrefix = "answer:config:id:"
diff --git a/internal/repo/export/email_repo.go b/internal/repo/export/email_repo.go
index 9552c4ac..59cba04b 100644
--- a/internal/repo/export/email_repo.go
+++ b/internal/repo/export/email_repo.go
@@ -21,6 +21,8 @@ package export
import (
"context"
+ "github.com/apache/incubator-answer/internal/base/constant"
+ "github.com/tidwall/gjson"
"time"
"github.com/apache/incubator-answer/internal/base/data"
@@ -42,9 +44,15 @@ func NewEmailRepo(data *data.Data) export.EmailRepo {
}
// SetCode The email code is used to verify that the link in the message is out of date
-func (e *emailRepo) SetCode(ctx context.Context, code, content string, duration time.Duration) error {
- err := e.data.Cache.SetString(ctx, code, content, duration)
- if err != nil {
+func (e *emailRepo) SetCode(ctx context.Context, userID, code, content string, duration time.Duration) error {
+ // Setting the latest code is to help ensure that only one link is active at a time.
+ // Set userID -> latest code
+ if err := e.data.Cache.SetString(ctx, constant.UserLatestEmailCodeCacheKey+userID, code, duration); err != nil {
+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ }
+
+ // Set latest code -> content
+ if err := e.data.Cache.SetString(ctx, constant.UserEmailCodeCacheKey+code, content, duration); err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return nil
@@ -52,12 +60,39 @@ func (e *emailRepo) SetCode(ctx context.Context, code, content string, duration
// VerifyCode verify the code if out of date
func (e *emailRepo) VerifyCode(ctx context.Context, code string) (content string, err error) {
- content, exist, err := e.data.Cache.GetString(ctx, code)
+ // Get latest code -> content
+ codeCacheKey := constant.UserEmailCodeCacheKey + code
+ content, exist, err := e.data.Cache.GetString(ctx, codeCacheKey)
if err != nil {
return "", err
}
if !exist {
return "", nil
}
+
+ // Delete the code after verification
+ _ = e.data.Cache.Del(ctx, codeCacheKey)
+
+ // If some email content does not need to verify the latest code is the same as the code, skip it.
+ // For example, some unsubscribe email content does not need to verify the latest code.
+ // This link always works before the code is out of date.
+ if skipValidationLatestCode := gjson.Get(content, "skip_validation_latest_code").Bool(); skipValidationLatestCode {
+ return content, nil
+ }
+ userID := gjson.Get(content, "user_id").String()
+
+ // Get userID -> latest code
+ latestCode, exist, err := e.data.Cache.GetString(ctx, constant.UserLatestEmailCodeCacheKey+userID)
+ if err != nil {
+ return "", err
+ }
+ if !exist {
+ return "", nil
+ }
+
+ // Check if the latest code is the same as the code, if not, means the code is out of date
+ if latestCode != code {
+ return "", nil
+ }
return content, nil
}
diff --git a/internal/schema/email_template.go b/internal/schema/email_template.go
index 9a6be794..56d3ee4e 100644
--- a/internal/schema/email_template.go
+++ b/internal/schema/email_template.go
@@ -42,6 +42,8 @@ type EmailCodeContent struct {
NotificationSources []constant.NotificationSource `json:"notification_source,omitempty"`
// Used for third-party login account binding
BindingKey string `json:"binding_key,omitempty"`
+ // Skip the validation of the latest code
+ SkipValidationLatestCode bool `json:"skip_validation_latest_code"`
}
func (r *EmailCodeContent) ToJSONString() string {
diff --git a/internal/service/content/user_service.go b/internal/service/content/user_service.go
index a2b33005..11f3bb63 100644
--- a/internal/service/content/user_service.go
+++ b/internal/service/content/user_service.go
@@ -227,7 +227,7 @@ func (us *UserService) RetrievePassWord(ctx context.Context, req *schema.UserRet
if err != nil {
return err
}
- go us.emailService.SendAndSaveCode(ctx, req.Email, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, req.Email, title, body, code, data.ToJSONString())
return nil
}
@@ -450,7 +450,7 @@ func (us *UserService) UserRegisterByEmail(ctx context.Context, registerUserInfo
if err != nil {
return nil, nil, err
}
- go us.emailService.SendAndSaveCode(ctx, userInfo.EMail, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, userInfo.EMail, title, body, code, data.ToJSONString())
roleID, err := us.userRoleService.GetUserRole(ctx, userInfo.ID)
if err != nil {
@@ -500,7 +500,7 @@ func (us *UserService) UserVerifyEmailSend(ctx context.Context, userID string) e
if err != nil {
return err
}
- go us.emailService.SendAndSaveCode(ctx, userInfo.EMail, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, userInfo.EMail, title, body, code, data.ToJSONString())
return nil
}
@@ -621,7 +621,7 @@ func (us *UserService) UserChangeEmailSendCode(ctx context.Context, req *schema.
}
log.Infof("send email confirmation %s", verifyEmailURL)
- go us.emailService.SendAndSaveCode(ctx, req.Email, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, req.Email, title, body, code, data.ToJSONString())
return nil, nil
}
diff --git a/internal/service/export/email_service.go b/internal/service/export/email_service.go
index 03d9c182..ae5d337a 100644
--- a/internal/service/export/email_service.go
+++ b/internal/service/export/email_service.go
@@ -51,7 +51,7 @@ type EmailService struct {
// EmailRepo email repository
type EmailRepo interface {
- SetCode(ctx context.Context, code, content string, duration time.Duration) error
+ SetCode(ctx context.Context, userID, code, content string, duration time.Duration) error
VerifyCode(ctx context.Context, code string) (content string, err error)
}
@@ -89,30 +89,32 @@ func (e *EmailConfig) IsTLS() bool {
}
// SaveCode save code
-func (es *EmailService) SaveCode(ctx context.Context, code, codeContent string) {
- err := es.emailRepo.SetCode(ctx, code, codeContent, 10*time.Minute)
+func (es *EmailService) SaveCode(ctx context.Context, userID, code, codeContent string) {
+ err := es.emailRepo.SetCode(ctx, userID, code, codeContent, constant.UserEmailCodeCacheTime)
if err != nil {
log.Error(err)
}
}
// SendAndSaveCode send email and save code
-func (es *EmailService) SendAndSaveCode(ctx context.Context, toEmailAddr, subject, body, code, codeContent string) {
- es.Send(ctx, toEmailAddr, subject, body)
- err := es.emailRepo.SetCode(ctx, code, codeContent, 10*time.Minute)
+func (es *EmailService) SendAndSaveCode(ctx context.Context, userID, toEmailAddr, subject, body, code, codeContent string) {
+ err := es.emailRepo.SetCode(ctx, userID, code, codeContent, constant.UserEmailCodeCacheTime)
if err != nil {
log.Error(err)
+ return
}
+ es.Send(ctx, toEmailAddr, subject, body)
}
// SendAndSaveCodeWithTime send email and save code
func (es *EmailService) SendAndSaveCodeWithTime(
- ctx context.Context, toEmailAddr, subject, body, code, codeContent string, duration time.Duration) {
- es.Send(ctx, toEmailAddr, subject, body)
- err := es.emailRepo.SetCode(ctx, code, codeContent, duration)
+ ctx context.Context, userID, toEmailAddr, subject, body, code, codeContent string, duration time.Duration) {
+ err := es.emailRepo.SetCode(ctx, userID, code, codeContent, duration)
if err != nil {
log.Error(err)
+ return
}
+ es.Send(ctx, toEmailAddr, subject, body)
}
// Send email send
diff --git a/internal/service/notification/invite_answer_notification.go b/internal/service/notification/invite_answer_notification.go
index 1122d052..503caa51 100644
--- a/internal/service/notification/invite_answer_notification.go
+++ b/internal/service/notification/invite_answer_notification.go
@@ -59,8 +59,9 @@ func (ns *ExternalNotificationService) sendInviteAnswerNotificationEmail(ctx con
NotificationSources: []constant.NotificationSource{
constant.InboxSource,
},
- Email: email,
- UserID: userID,
+ Email: email,
+ UserID: userID,
+ SkipValidationLatestCode: true,
}
// If receiver has set language, use it to send email.
@@ -74,5 +75,5 @@ func (ns *ExternalNotificationService) sendInviteAnswerNotificationEmail(ctx con
}
ns.emailService.SendAndSaveCodeWithTime(
- ctx, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
+ ctx, userID, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
}
diff --git a/internal/service/notification/new_answer_notification.go b/internal/service/notification/new_answer_notification.go
index 4a43192f..1e08b455 100644
--- a/internal/service/notification/new_answer_notification.go
+++ b/internal/service/notification/new_answer_notification.go
@@ -59,8 +59,9 @@ func (ns *ExternalNotificationService) sendNewAnswerNotificationEmail(ctx contex
NotificationSources: []constant.NotificationSource{
constant.InboxSource,
},
- Email: email,
- UserID: userID,
+ Email: email,
+ UserID: userID,
+ SkipValidationLatestCode: true,
}
// If receiver has set language, use it to send email.
@@ -74,5 +75,5 @@ func (ns *ExternalNotificationService) sendNewAnswerNotificationEmail(ctx contex
}
ns.emailService.SendAndSaveCodeWithTime(
- ctx, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
+ ctx, userID, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
}
diff --git a/internal/service/notification/new_comment_notification.go b/internal/service/notification/new_comment_notification.go
index 048c66f1..5e2dce7b 100644
--- a/internal/service/notification/new_comment_notification.go
+++ b/internal/service/notification/new_comment_notification.go
@@ -59,8 +59,9 @@ func (ns *ExternalNotificationService) sendNewCommentNotificationEmail(ctx conte
NotificationSources: []constant.NotificationSource{
constant.InboxSource,
},
- Email: email,
- UserID: userID,
+ Email: email,
+ UserID: userID,
+ SkipValidationLatestCode: true,
}
// If receiver has set language, use it to send email.
if len(lang) > 0 {
@@ -73,5 +74,5 @@ func (ns *ExternalNotificationService) sendNewCommentNotificationEmail(ctx conte
}
ns.emailService.SendAndSaveCodeWithTime(
- ctx, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
+ ctx, userID, email, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
}
diff --git a/internal/service/notification/new_question_notification.go b/internal/service/notification/new_question_notification.go
index d4173397..08a77488 100644
--- a/internal/service/notification/new_question_notification.go
+++ b/internal/service/notification/new_question_notification.go
@@ -189,9 +189,10 @@ func (ns *ExternalNotificationService) sendNewQuestionNotificationEmail(ctx cont
constant.AllNewQuestionSource,
constant.AllNewQuestionForFollowingTagsSource,
},
+ SkipValidationLatestCode: true,
}
ns.emailService.SendAndSaveCodeWithTime(
- ctx, userInfo.EMail, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
+ ctx, userInfo.ID, userInfo.EMail, title, body, rawData.UnsubscribeCode, codeContent.ToJSONString(), 1*24*time.Hour)
}
func (ns *ExternalNotificationService) syncNewQuestionNotificationToPlugin(ctx context.Context,
diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index f82a7c7f..74027ec2 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -274,7 +274,7 @@ func (s *SiteInfoService) UpdateSMTPConfig(ctx context.Context, req *schema.Upda
if err != nil {
return err
}
- go s.emailService.SendAndSaveCode(ctx, req.TestEmailRecipient, title, body, "", "")
+ go s.emailService.Send(ctx, req.TestEmailRecipient, title, body)
}
return nil
}
diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.go
index 6ce98f99..72b9c255 100644
--- a/internal/service/user_admin/user_backyard.go
+++ b/internal/service/user_admin/user_backyard.go
@@ -513,7 +513,7 @@ func (us *UserAdminService) setUserRoleInfo(ctx context.Context, resp []*schema.
func (us *UserAdminService) GetUserActivation(ctx context.Context, req *schema.GetUserActivationReq) (
resp *schema.GetUserActivationResp, err error) {
- user, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
+ userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
if err != nil {
return nil, err
}
@@ -527,11 +527,11 @@ func (us *UserAdminService) GetUserActivation(ctx context.Context, req *schema.G
}
data := &schema.EmailCodeContent{
- Email: user.EMail,
- UserID: user.ID,
+ Email: userInfo.EMail,
+ UserID: userInfo.ID,
}
code := uuid.NewString()
- us.emailService.SaveCode(ctx, code, data.ToJSONString())
+ us.emailService.SaveCode(ctx, userInfo.ID, code, data.ToJSONString())
resp = &schema.GetUserActivationResp{
ActivationURL: fmt.Sprintf("%s/users/account-activation?code=%s", general.SiteUrl, code),
}
@@ -540,7 +540,7 @@ func (us *UserAdminService) GetUserActivation(ctx context.Context, req *schema.G
// SendUserActivation send user activation email
func (us *UserAdminService) SendUserActivation(ctx context.Context, req *schema.SendUserActivationReq) (err error) {
- user, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
+ userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
if err != nil {
return err
}
@@ -554,17 +554,16 @@ func (us *UserAdminService) SendUserActivation(ctx context.Context, req *schema.
}
data := &schema.EmailCodeContent{
- Email: user.EMail,
- UserID: user.ID,
+ Email: userInfo.EMail,
+ UserID: userInfo.ID,
}
code := uuid.NewString()
- us.emailService.SaveCode(ctx, code, data.ToJSONString())
verifyEmailURL := fmt.Sprintf("%s/users/account-activation?code=%s", general.SiteUrl, code)
title, body, err := us.emailService.RegisterTemplate(ctx, verifyEmailURL)
if err != nil {
return err
}
- go us.emailService.SendAndSaveCode(ctx, user.EMail, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, userInfo.EMail, title, body, code, data.ToJSONString())
return nil
}
diff --git a/internal/service/user_external_login/user_external_login_service.go b/internal/service/user_external_login/user_external_login_service.go
index 0923908f..3b70a535 100644
--- a/internal/service/user_external_login/user_external_login_service.go
+++ b/internal/service/user_external_login/user_external_login_service.go
@@ -328,7 +328,7 @@ func (us *UserExternalLoginService) ExternalLoginBindingUserSendEmail(
if err != nil {
return nil, err
}
- go us.emailService.SendAndSaveCode(ctx, userInfo.EMail, title, body, code, data.ToJSONString())
+ go us.emailService.SendAndSaveCode(ctx, userInfo.ID, userInfo.EMail, title, body, code, data.ToJSONString())
return resp, nil
}
(incubator-answer) 04/05: fix(question): update answer count after reviewing
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 8f30a1530cd2c354c16eeb6043e779502980515b
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Jul 25 10:09:51 2024 +0800
fix(question): update answer count after reviewing
---
cmd/wire_gen.go | 2 +-
internal/service/review/review_service.go | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index e7ff464c..1e69c751 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -193,7 +193,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
answerActivityService := activity2.NewAnswerActivityService(answerActivityRepo, configService)
externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, externalNotificationQueueService, userExternalLoginRepo, siteInfoCommonService)
reviewRepo := review.NewReviewRepo(dataData)
- reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, externalNotificationQueueService, tagCommonService, notificationQueueService, siteInfoCommonService)
+ reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, externalNotificationQueueService, tagCommonService, questionCommon, notificationQueueService, siteInfoCommonService)
questionService := content.NewQuestionService(questionRepo, tagCommonService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService, reviewService, configService)
answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, notificationQueueService, externalNotificationQueueService, activityQueueService, reviewService)
reportHandle := report_handle.NewReportHandle(questionService, answerService, commentService)
diff --git a/internal/service/review/review_service.go b/internal/service/review/review_service.go
index ab4079ee..fb323178 100644
--- a/internal/service/review/review_service.go
+++ b/internal/service/review/review_service.go
@@ -63,6 +63,7 @@ type ReviewService struct {
answerRepo answercommon.AnswerRepo
userRoleService *role.UserRoleRelService
tagCommon *tagcommon.TagCommonService
+ questionCommon *questioncommon.QuestionCommon
externalNotificationQueueService notice_queue.ExternalNotificationQueueService
notificationQueueService notice_queue.NotificationQueueService
siteInfoService siteinfo_common.SiteInfoCommonService
@@ -79,6 +80,7 @@ func NewReviewService(
userRoleService *role.UserRoleRelService,
externalNotificationQueueService notice_queue.ExternalNotificationQueueService,
tagCommon *tagcommon.TagCommonService,
+ questionCommon *questioncommon.QuestionCommon,
notificationQueueService notice_queue.NotificationQueueService,
siteInfoService siteinfo_common.SiteInfoCommonService,
) *ReviewService {
@@ -92,6 +94,7 @@ func NewReviewService(
userRoleService: userRoleService,
externalNotificationQueueService: externalNotificationQueueService,
tagCommon: tagCommon,
+ questionCommon: questionCommon,
notificationQueueService: notificationQueueService,
siteInfoService: siteInfoService,
}
@@ -295,6 +298,12 @@ func (cs *ReviewService) updateObjectStatus(ctx context.Context, review *entity.
cs.notificationAnswerTheQuestion(ctx, questionInfo.UserID, questionInfo.ID, answerInfo.ID,
answerInfo.UserID, questionInfo.Title, answerInfo.OriginalText)
}
+ if err := cs.questionCommon.UpdateAnswerCount(ctx, answerInfo.QuestionID); err != nil {
+ log.Errorf("update question answer count failed, err: %v", err)
+ }
+ if err := cs.questionCommon.UpdateLastAnswer(ctx, answerInfo.QuestionID, uid.DeShortID(answerInfo.ID)); err != nil {
+ log.Errorf("update question last answer failed, err: %v", err)
+ }
userAnswerCount, err := cs.answerRepo.GetCountByUserID(ctx, answerInfo.UserID)
if err != nil {
log.Errorf("get user answer count failed, err: %v", err)
(incubator-answer) 05/05: Merge branch 'dev' into feat/1.3.6/user
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 8cb5dd993f35af993f880ed7cb7c0565a677f3c7
Merge: 8f30a153 bbefbbcb
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Jul 25 10:10:34 2024 +0800
Merge branch 'dev' into feat/1.3.6/user
docs/docs.go | 28 +++++++++++++++-------------
docs/swagger.json | 28 +++++++++++++++-------------
docs/swagger.yaml | 22 +++++++++++++---------
i18n/en_US.yaml | 3 +++
internal/controller/meta_controller.go | 2 +-
internal/repo/user/user_repo.go | 2 +-
internal/schema/backyard_user_schema.go | 1 +
internal/service/user_admin/user_backyard.go | 1 +
ui/src/hooks/useChangeProfileModal/index.tsx | 23 +++++++++++++++++++++--
ui/src/services/admin/users.ts | 1 +
10 files changed, 72 insertions(+), 39 deletions(-)