fix(answer): Only the admin and author can view the deleted answer.

This commit is contained in:
LinkinStars 2023-03-01 17:28:16 +08:00
parent 88e11d117e
commit c3d8d30892
5 changed files with 11 additions and 4 deletions

View File

@ -35,6 +35,8 @@ type Answer struct {
type AnswerSearch struct {
Answer
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

View File

@ -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)

View File

@ -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"`

View File

@ -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
}

View File

@ -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