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: enhance answer visibility checks for user permissions

LinkinStarsc589b59dd5f1
diff --git a/internal/service/content/answer_service.go b/internal/service/content/answer_service.go
index 25b0050e..bda7b582 100644
--- a/internal/service/content/answer_service.go
+++ b/internal/service/content/answer_service.go
@@ -554,12 +554,18 @@ func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string,
if !exist {
return nil, nil, false, errors.NotFound(reason.AnswerNotFound)
}
+
if (question.Status == entity.QuestionStatusDeleted ||
question.Status == entity.QuestionStatusPending ||
question.Show == entity.QuestionHide) &&
!isAdminModerator && question.UserID != loginUserID {
return nil, nil, false, errors.NotFound(reason.AnswerNotFound)
}
+ if (answerInfo.Status == entity.AnswerStatusDeleted ||
+ answerInfo.Status == entity.AnswerStatusPending) &&
+ !isAdminModerator && answerInfo.UserID != loginUserID {
+ return nil, nil, false, errors.NotFound(reason.AnswerNotFound)
+ }
info := as.ShowFormat(ctx, answerInfo)
// todo questionFunc
questionInfo, err := as.questionCommon.Info(ctx, answerInfo.QuestionID, loginUserID)