Merge branch 'feat/1.0.7/short-id' into test

This commit is contained in:
aichy126 2023-03-15 17:35:47 +08:00
commit 28d76b5e13
5 changed files with 11 additions and 0 deletions

View File

@ -48,6 +48,8 @@ backend:
other: No permission to delete.
cannot_update:
other: No permission to update.
question_closed_cannot_add:
other: Questions are closed and cannot be added.
comment:
edit_without_permission:
other: Comment are not allowed to edit.

View File

@ -44,6 +44,8 @@ backend:
other: 没有删除权限。
cannot_update:
other: 没有更新权限。
question_closed_cannot_add:
other: 问题已关闭不可以新增回答
comment:
edit_without_permission:
other: 不允许编辑评论。

View File

@ -25,6 +25,7 @@ const (
AnswerNotFound = "error.answer.not_found"
AnswerCannotDeleted = "error.answer.cannot_deleted"
AnswerCannotUpdate = "error.answer.cannot_update"
AnswerCannotAddByClosedQuestion = "error.answer.question_closed_cannot_add"
CommentEditWithoutPermission = "error.comment.edit_without_permission"
DisallowVote = "error.object.disallow_vote"
DisallowFollow = "error.object.disallow_follow"

View File

@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/service/activity"
"github.com/answerdev/answer/internal/service/activity_common"
"github.com/answerdev/answer/internal/service/role"
"github.com/answerdev/answer/pkg/uid"
"github.com/gin-gonic/gin"
)
@ -38,6 +39,7 @@ func (ac *ActivityController) GetObjectTimeline(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.ObjectID = uid.DeShortID(req.ObjectID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
if userInfo := middleware.GetUserInfoFromContext(ctx); userInfo != nil {

View File

@ -146,6 +146,10 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
if !exist {
return "", errors.BadRequest(reason.QuestionNotFound)
}
if questionInfo.Status == entity.QuestionStatusClosed || questionInfo.Status == entity.QuestionStatusDeleted {
err = errors.BadRequest(reason.AnswerCannotAddByClosedQuestion)
return "", err
}
insertData := new(entity.Answer)
insertData.UserID = req.UserID
insertData.OriginalText = req.Content