Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update answer

aichy126cf2fc12e382f
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 18d311c3..75522e52 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -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.
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index 604c7e23..85b2ec79 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -44,6 +44,8 @@ backend:
other: 没有删除权限。
cannot_update:
other: 没有更新权限。
+ question_closed_cannot_add:
+ other: 问题已关闭不可以新增回答
comment:
edit_without_permission:
other: 不允许编辑评论。
diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go
index 17c00070..e0915b97 100644
--- a/internal/base/reason/reason.go
+++ b/internal/base/reason/reason.go
@@ -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"
diff --git a/internal/controller/activity_controller.go b/internal/controller/activity_controller.go
index 917e1634..8f8e6f20 100644
--- a/internal/controller/activity_controller.go
+++ b/internal/controller/activity_controller.go
@@ -6,6 +6,7 @@ import (
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/activity"
"github.com/answerdev/answer/internal/service/activity_common"
+ "github.com/answerdev/answer/pkg/uid"
"github.com/gin-gonic/gin"
)
@@ -37,6 +38,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 {
diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go
index 5d854b5d..1860bf7d 100644
--- a/internal/service/answer_service.go
+++ b/internal/service/answer_service.go
@@ -138,6 +138,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