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(answer): Only the admin and author can view the deleted answer.
LinkinStarsc3d8d308923d
diff --git a/internal/entity/answer_entity.go b/internal/entity/answer_entity.goindex 8c3bcdb1..43567efd 100644--- a/internal/entity/answer_entity.go+++ b/internal/entity/answer_entity.go@@ -35,9 +35,11 @@ type Answer struct {type AnswerSearch struct {Answer- Order string `json:"order_by" ` // default or updated- Page int `json:"page" form:"page"` // Query number of pages- PageSize int `json:"page_size" form:"page_size"` // Search page size+ IncludeDeleted bool `json:"include_deleted"`+ LoginUserID string `json:"login_user_id"`+ Order string `json:"order_by"` // default or updated+ Page int `json:"page" form:"page"` // Query number of pages+ PageSize int `json:"page_size" form:"page_size"` // Search page size}type AdminAnswerSearch struct {diff --git a/internal/repo/answer/answer_repo.go b/internal/repo/answer/answer_repo.goindex 97734343..046d22dc 100644--- a/internal/repo/answer/answer_repo.go+++ b/internal/repo/answer/answer_repo.go@@ -206,7 +206,9 @@ func (ar *answerRepo) SearchList(ctx context.Context, search *entity.AnswerSearcdefault:session = session.OrderBy("adopted desc,vote_count desc,created_at asc")}- session = session.And("status = ?", entity.AnswerStatusAvailable)+ if !search.IncludeDeleted {+ session = session.And("status = ? OR user_id = ?", entity.AnswerStatusAvailable, search.UserID)+ }session = session.Limit(search.PageSize, offset)count, err = session.FindAndCount(&rows)diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.goindex 7fc6a12d..3a67f2bf 100644--- a/internal/schema/answer_schema.go+++ b/internal/schema/answer_schema.go@@ -83,6 +83,7 @@ type AnswerInfo struct {VoteStatus string `json:"vote_status"`VoteCount int `json:"vote_count"`QuestionInfo *QuestionInfo `json:"question_info,omitempty"`+ Status int `json:"status"`// MemberActionsMemberActions []*PermissionMemberAction `json:"member_actions"`diff --git a/internal/service/answer_common/answer.go b/internal/service/answer_common/answer.goindex 758908e1..357484f2 100644--- a/internal/service/answer_common/answer.go+++ b/internal/service/answer_common/answer.go@@ -73,6 +73,7 @@ func (as *AnswerCommon) ShowFormat(ctx context.Context, data *entity.Answer) *sc}info.UserID = data.UserIDinfo.UpdateUserID = data.LastEditUserID+ info.Status = data.Statusreturn &info}diff --git a/internal/service/answer_service.go b/internal/service/answer_service.goindex 974482c9..d4d49076 100644--- a/internal/service/answer_service.go+++ b/internal/service/answer_service.go@@ -473,6 +473,7 @@ func (as *AnswerService) SearchList(ctx context.Context, req *schema.AnswerListRdbSearch.Page = req.PagedbSearch.PageSize = req.PageSizedbSearch.Order = req.Order+ dbSearch.IncludeDeleted = req.CanDeleteanswerOriginalList, count, err := as.answerRepo.SearchList(ctx, &dbSearch)if err != nil {return list, count, err