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.

fix(comment): prohibit comment on the delete content

LinkinStars410263e676a2
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 0221cfa0..24b02f5b 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -139,6 +139,8 @@ backend:
other: Password
pass:
other: Password
+ original_text:
+ other: This post
email_or_password_wrong_error:
other: Email and password do not match.
error:
@@ -202,6 +204,8 @@ backend:
other: The old password verification failed
new_password_same_as_previous_setting:
other: The new password is the same as the previous one.
+ already_deleted:
+ other: This post has been deleted.
question:
already_deleted:
other: This post has been deleted.
diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go
index 0dbf73ac..4bc7a88a 100644
--- a/internal/base/reason/reason.go
+++ b/internal/base/reason/reason.go
@@ -58,6 +58,7 @@ const (
CaptchaVerificationFailed = "error.object.captcha_verification_failed"
OldPasswordVerificationFailed = "error.object.old_password_verification_failed"
NewPasswordSameAsPreviousSetting = "error.object.new_password_same_as_previous_setting"
+ NewObjectAlreadyDeleted = "error.object.already_deleted"
UserNotFound = "error.user.not_found"
UsernameInvalid = "error.user.username_invalid"
UsernameDuplicate = "error.user.username_duplicate"
diff --git a/internal/schema/simple_obj_info_schema.go b/internal/schema/simple_obj_info_schema.go
index 7c4fa9af..3a3f7810 100644
--- a/internal/schema/simple_obj_info_schema.go
+++ b/internal/schema/simple_obj_info_schema.go
@@ -19,20 +19,40 @@
package schema
+import (
+ "github.com/apache/incubator-answer/internal/base/constant"
+ "github.com/apache/incubator-answer/internal/entity"
+)
+
// SimpleObjectInfo simple object info
type SimpleObjectInfo struct {
ObjectID string `json:"object_id"`
ObjectCreatorUserID string `json:"object_creator_user_id"`
QuestionID string `json:"question_id"`
- QuestionStatus int `json:"status"`
+ QuestionStatus int `json:"question_status"`
AnswerID string `json:"answer_id"`
+ AnswerStatus int `json:"answer_status"`
CommentID string `json:"comment_id"`
+ CommentStatus int `json:"comment_status"`
TagID string `json:"tag_id"`
ObjectType string `json:"object_type"`
Title string `json:"title"`
Content string `json:"content"`
}
+// IsDeleted is deleted
+func (s *SimpleObjectInfo) IsDeleted() bool {
+ switch s.ObjectType {
+ case constant.QuestionObjectType:
+ return s.QuestionStatus == entity.QuestionStatusDeleted
+ case constant.AnswerObjectType:
+ return s.AnswerStatus == entity.AnswerStatusDeleted
+ case constant.CommentObjectType:
+ return s.CommentStatus == entity.CommentStatusDeleted
+ }
+ return false
+}
+
type UnreviewedRevisionInfoInfo struct {
CreatedAt int64 `json:"created_at"`
ObjectID string `json:"object_id"`
diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.go
index a689a95d..9f2c45f1 100644
--- a/internal/service/comment/comment_service.go
+++ b/internal/service/comment/comment_service.go
@@ -122,11 +122,13 @@ func (cs *CommentService) AddComment(ctx context.Context, req *schema.AddComment
_ = copier.Copy(comment, req)
comment.Status = entity.CommentStatusAvailable
- // add question id
objInfo, err := cs.objectInfoService.GetInfo(ctx, req.ObjectID)
if err != nil {
return nil, err
}
+ if objInfo.IsDeleted() {
+ return nil, errors.BadRequest(reason.NewObjectAlreadyDeleted)
+ }
objInfo.ObjectID = uid.DeShortID(objInfo.ObjectID)
objInfo.QuestionID = uid.DeShortID(objInfo.QuestionID)
objInfo.AnswerID = uid.DeShortID(objInfo.AnswerID)
diff --git a/internal/service/content/vote_service.go b/internal/service/content/vote_service.go
index 9785e30d..bfb403c9 100644
--- a/internal/service/content/vote_service.go
+++ b/internal/service/content/vote_service.go
@@ -88,6 +88,9 @@ func (vs *VoteService) VoteUp(ctx context.Context, req *schema.VoteReq) (resp *s
if err != nil {
return nil, err
}
+ if objectInfo.IsDeleted() {
+ return nil, errors.BadRequest(reason.NewObjectAlreadyDeleted)
+ }
// make object id must be decoded
objectInfo.ObjectID = req.ObjectID
@@ -132,6 +135,9 @@ func (vs *VoteService) VoteDown(ctx context.Context, req *schema.VoteReq) (resp
if err != nil {
return nil, err
}
+ if objectInfo.IsDeleted() {
+ return nil, errors.BadRequest(reason.NewObjectAlreadyDeleted)
+ }
// make object id must be decoded
objectInfo.ObjectID = req.ObjectID
diff --git a/internal/service/object_info/object_info.go b/internal/service/object_info/object_info.go
index 0e1dbdc2..6c2e89a9 100644
--- a/internal/service/object_info/object_info.go
+++ b/internal/service/object_info/object_info.go
@@ -228,6 +228,7 @@ func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *sc
ObjectCreatorUserID: answerInfo.UserID,
QuestionID: answerInfo.QuestionID,
QuestionStatus: questionInfo.Status,
+ AnswerStatus: answerInfo.Status,
AnswerID: answerInfo.ID,
ObjectType: objectType,
Title: questionInfo.Title, // this should be question title
@@ -247,6 +248,7 @@ func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *sc
ObjectType: objectType,
Content: commentInfo.ParsedText, // todo trim
CommentID: commentInfo.ID,
+ CommentStatus: commentInfo.Status,
}
if len(commentInfo.QuestionID) > 0 {
questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, commentInfo.QuestionID)
diff --git a/internal/service/report/report_service.go b/internal/service/report/report_service.go
index f25fb351..7f060a39 100644
--- a/internal/service/report/report_service.go
+++ b/internal/service/report/report_service.go
@@ -91,6 +91,9 @@ func (rs *ReportService) AddReport(ctx context.Context, req *schema.AddReportReq
if err != nil {
return err
}
+ if objInfo.IsDeleted() {
+ return errors.BadRequest(reason.NewObjectAlreadyDeleted)
+ }
cf, err := rs.configService.GetConfigByID(ctx, req.ReportType)
if err != nil || cf == nil {