mirror of https://gitee.com/answerdev/answer.git
feat(question): Only the admin and author can view the deleted post.
This commit is contained in:
parent
7ec0272a72
commit
88e11d117e
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -170,10 +170,11 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser
|
|||
log.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.OperationLevelInfo
|
||||
showinfo.Operation = operation
|
||||
}
|
||||
|
||||
|
|
|
@ -614,12 +614,23 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID s
|
|||
if 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)
|
||||
|
|
Loading…
Reference in New Issue