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(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.go
index 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.go
index 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.AnswerSearc
default:
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.go
index 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"`
// MemberActions
MemberActions []*PermissionMemberAction `json:"member_actions"`
diff --git a/internal/service/answer_common/answer.go b/internal/service/answer_common/answer.go
index 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.UserID
info.UpdateUserID = data.LastEditUserID
+ info.Status = data.Status
return &info
}
diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go
index 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.AnswerListR
dbSearch.Page = req.Page
dbSearch.PageSize = req.PageSize
dbSearch.Order = req.Order
+ dbSearch.IncludeDeleted = req.CanDelete
answerOriginalList, count, err := as.answerRepo.SearchList(ctx, &dbSearch)
if err != nil {
return list, count, err