mirror of https://gitee.com/answerdev/answer.git
fix admin update question
This commit is contained in:
parent
7f7d11f58c
commit
5b005e652f
|
@ -270,13 +270,40 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
||||||
if !has {
|
if !has {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// If it's not admin
|
||||||
if !req.IsAdmin {
|
if !req.IsAdmin {
|
||||||
if dbinfo.UserID != req.UserID {
|
if dbinfo.UserID != req.UserID {
|
||||||
return questionInfo, errors.BadRequest(reason.QuestionCannotUpdate)
|
return questionInfo, errors.BadRequest(reason.QuestionCannotUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
//CheckChangeTag
|
||||||
|
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
|
||||||
|
if err != nil {
|
||||||
|
return questionInfo, tagerr
|
||||||
|
}
|
||||||
|
tagNameList := make([]string, 0)
|
||||||
|
for _, tag := range req.Tags {
|
||||||
|
tagNameList = append(tagNameList, tag.SlugName)
|
||||||
|
}
|
||||||
|
Tags, tagerr := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
|
||||||
|
if err != nil {
|
||||||
|
return questionInfo, tagerr
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckTag, CheckTaglist := qs.CheckChangeReservedTag(ctx, oldTags, Tags)
|
||||||
|
if !CheckTag {
|
||||||
|
errMsg := fmt.Sprintf(`The reserved tag %s must be present.`,
|
||||||
|
strings.Join(CheckTaglist, ","))
|
||||||
|
errorlist := make([]*validator.FormErrorField, 0)
|
||||||
|
errorlist = append(errorlist, &validator.FormErrorField{
|
||||||
|
ErrorField: "tags",
|
||||||
|
ErrorMsg: errMsg,
|
||||||
|
})
|
||||||
|
err = errors.BadRequest(reason.RequestFormatError).WithMsg(errMsg)
|
||||||
|
return errorlist, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check whether mandatory labels are selected
|
||||||
recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)
|
recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -291,33 +318,6 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
||||||
return errorlist, err
|
return errorlist, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//CheckChangeTag
|
|
||||||
oldTags, err := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tagNameList := make([]string, 0)
|
|
||||||
for _, tag := range req.Tags {
|
|
||||||
tagNameList = append(tagNameList, tag.SlugName)
|
|
||||||
}
|
|
||||||
Tags, err := qs.tagCommon.GetTagListByNames(ctx, tagNameList)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckTag, CheckTaglist := qs.CheckChangeReservedTag(ctx, oldTags, Tags)
|
|
||||||
if !CheckTag {
|
|
||||||
errMsg := fmt.Sprintf(`The reserved tag %s must be present.`,
|
|
||||||
strings.Join(CheckTaglist, ","))
|
|
||||||
errorlist := make([]*validator.FormErrorField, 0)
|
|
||||||
errorlist = append(errorlist, &validator.FormErrorField{
|
|
||||||
ErrorField: "tags",
|
|
||||||
ErrorMsg: errMsg,
|
|
||||||
})
|
|
||||||
err = errors.BadRequest(reason.RequestFormatError).WithMsg(errMsg)
|
|
||||||
return errorlist, err
|
|
||||||
}
|
|
||||||
|
|
||||||
//update question to db
|
//update question to db
|
||||||
err = qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"})
|
err = qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue