Merge remote-tracking branch 'origin/feat/1.0.2/user' into test

This commit is contained in:
LinkinStar 2022-12-28 17:29:29 +08:00
commit d6f25f3057
5 changed files with 12 additions and 23 deletions

View File

@ -25,6 +25,9 @@ func addThemeAndPrivateMode(x *xorm.Engine) error {
}
if !exist {
_, err = x.InsertOne(siteInfo)
if err != nil {
return fmt.Errorf("insert site info failed: %w", err)
}
}
themeConfig := `{"theme":"default","theme_config":{"default":{"navbar_style":"colored","primary_color":"#0033ff"}}}`

View File

@ -3,6 +3,7 @@ package repo_test
import (
"context"
"testing"
"time"
"github.com/answerdev/answer/internal/repo/export"
"github.com/stretchr/testify/assert"
@ -11,7 +12,7 @@ import (
func Test_emailRepo_VerifyCode(t *testing.T) {
emailRepo := export.NewEmailRepo(testDataSource)
code, content := "1111", "test"
err := emailRepo.SetCode(context.TODO(), code, content)
err := emailRepo.SetCode(context.TODO(), code, content, time.Minute)
assert.NoError(t, err)
verifyContent, err := emailRepo.VerifyCode(context.TODO(), code)

View File

@ -343,21 +343,6 @@ func (cs *CommentService) convertCommentEntity2Resp(ctx context.Context, req *sc
return commentResp, nil
}
func (cs *CommentService) checkCommentWhetherOwner(ctx context.Context, userID, commentID string) error {
// check comment if user self
comment, exist, err := cs.commentCommonRepo.GetComment(ctx, commentID)
if err != nil {
return err
}
if !exist {
return errors.BadRequest(reason.CommentNotFound)
}
if comment.UserID != userID {
return errors.BadRequest(reason.CommentEditWithoutPermission)
}
return nil
}
func (cs *CommentService) checkIsVote(ctx context.Context, userID, commentID string) (isVote bool) {
status := cs.voteCommon.GetVoteStatus(ctx, commentID, userID)
return len(status) > 0

View File

@ -27,19 +27,19 @@ func NewSearchParser(tagCommonService *tag_common.TagCommonService, userCommon *
// but if match two type, it will return false
func (sp *SearchParser) ParseStructure(dto *schema.SearchDTO) (
searchType string,
// search all
// search all
userID string,
votes int,
// search questions
// search questions
notAccepted bool,
isQuestion bool,
views,
answers int,
// search answers
// search answers
accepted bool,
questionID string,
isAnswer bool,
// common fields
// common fields
tags,
words []string,
) {
@ -202,7 +202,7 @@ func (sp *SearchParser) parseUserID(query *string, currentUserID string) (userID
re := regexp.MustCompile(exprUserID)
res := re.FindStringSubmatch(q)
if strings.Index(q, exprMe) != -1 {
if strings.Contains(q, exprMe) {
userID = currentUserID
q = strings.ReplaceAll(q, exprMe, "")
} else if len(res) == 2 {

View File

@ -1,7 +1,7 @@
package htmltext
import (
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
@ -89,7 +89,7 @@ func GetPicByUrl(Url string) string {
return ""
}
defer res.Body.Close()
pix, err := ioutil.ReadAll(res.Body)
pix, err := io.ReadAll(res.Body)
if err != nil {
return ""
}