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.
feat(question): Only the admin and author can view the deleted post.
LinkinStars88e11d117eb9
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 69a39c12..e49aa827 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -81,6 +81,8 @@ backend:new_password_same_as_previous_setting:other: The new password is the same as the previous one.question:+ already_deleted:+ other: This post has been deleted.not_found:other: Question not found.cannot_deleted:diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yamlindex 82d85bd2..6ee59e27 100644--- a/i18n/zh_CN.yaml+++ b/i18n/zh_CN.yaml@@ -1,4 +1,5 @@#The following fields are used for back-end+backend:base:success:@@ -80,6 +81,8 @@ backend:new_password_same_as_previous_setting:other: 新密码与之前的设置相同question:+ already_deleted:+ other: 该内容已被删除not_found:other: 问题未找到cannot_deleted:diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.goindex a33e33cc..6b817661 100644--- a/internal/base/reason/reason.go+++ b/internal/base/reason/reason.go@@ -21,6 +21,7 @@ const (QuestionCannotDeleted = "error.question.cannot_deleted"QuestionCannotClose = "error.question.cannot_close"QuestionCannotUpdate = "error.question.cannot_update"+ QuestionAlreadyDeleted = "error.question.already_deleted"AnswerNotFound = "error.answer.not_found"AnswerCannotDeleted = "error.answer.cannot_deleted"AnswerCannotUpdate = "error.answer.cannot_update"diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex b656b834..b0101141 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -176,11 +176,20 @@ type AdminQuestionInfo struct {UserInfo *UserBasicInfo `json:"user_info"`}+type OperationLevel string++const (+ OperationLevelInfo OperationLevel = "info"+ OperationLevelDanger OperationLevel = "danger"+ OperationLevelWarning OperationLevel = "warning"+)+type Operation struct {- OperationType string `json:"operation_type"`- OperationDescription string `json:"operation_description"`- OperationMsg string `json:"operation_msg"`- OperationTime int64 `json:"operation_time"`+ Type string `json:"type"`+ Description string `json:"description"`+ Msg string `json:"msg"`+ Time int64 `json:"time"`+ Level OperationLevel `json:"level"`}type GetCloseTypeResp struct {diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.goindex b37e9099..3daeec06 100644--- a/internal/service/question_common/question.go+++ b/internal/service/question_common/question.go@@ -170,10 +170,11 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUserlog.Error("json.Unmarshal QuestionCloseJson error", err.Error())} else {operation := &schema.Operation{}- operation.OperationType = closeinfo.Name- operation.OperationDescription = closeinfo.Description- operation.OperationMsg = closemsg.CloseMsg- operation.OperationTime = metainfo.CreatedAt.Unix()+ operation.Type = closeinfo.Name+ operation.Description = closeinfo.Description+ operation.Msg = closemsg.CloseMsg+ operation.Time = metainfo.CreatedAt.Unix()+ operation.Level = schema.OperationLevelInfoshowinfo.Operation = operation}diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex a21523b5..ccf49454 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -614,12 +614,23 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID sif err != nil {return}+ // If the question is deleted, only the administrator and the author can view it+ if question.Status == entity.QuestionStatusDeleted && !per.CanReopen && question.UserID != userID {+ return nil, errors.NotFound(reason.QuestionNotFound)+ }if question.Status != entity.QuestionStatusClosed {per.CanReopen = false}if question.Status == entity.QuestionStatusClosed {per.CanClose = false}+ if question.Status == entity.QuestionStatusDeleted {+ operation := &schema.Operation{}+ operation.Msg = translator.Tr(handler.GetLangByCtx(ctx), reason.QuestionAlreadyDeleted)+ operation.Level = schema.OperationLevelDanger+ question.Operation = operation+ }+question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240)question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID,per.CanEdit, per.CanDelete, per.CanClose, per.CanReopen)