Skip to content

Commit

Permalink
fix issue:userprofile hide unlisted post(apache#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang Wong committed Dec 29, 2023
1 parent ec11a12 commit f8733c4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1,035 deletions.
26 changes: 3 additions & 23 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion internal/repo/question/question_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (qr *questionRepo) SitemapQuestions(ctx context.Context, page, pageSize int
}

// GetQuestionPage query question page
func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int) (
func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int, showHidden bool) (
questionList []*entity.Question, total int64, err error) {
questionList = make([]*entity.Question, 0)

Expand All @@ -357,6 +357,9 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
}
if len(userID) > 0 {
session.And("question.user_id = ?", userID)
if !showHidden {
session.And("question.show = ?", entity.QuestionShow)
}
} else {
session.And("question.show = ?", entity.QuestionShow)
}
Expand Down
19 changes: 0 additions & 19 deletions internal/service/mock/siteinfo_repo_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/question_common/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type QuestionRepo interface {
UpdateQuestion(ctx context.Context, question *entity.Question, Cols []string) (err error)
GetQuestion(ctx context.Context, id string) (question *entity.Question, exist bool, err error)
GetQuestionList(ctx context.Context, question *entity.Question) (questions []*entity.Question, err error)
GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int) (
GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int, showHidden bool) (
questionList []*entity.Question, total int64, err error)
UpdateQuestionStatus(ctx context.Context, questionID string, status int) (err error)
UpdateQuestionStatusWithOutUpdateTime(ctx context.Context, question *entity.Question) (err error)
Expand Down
19 changes: 17 additions & 2 deletions internal/service/question_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/apache/incubator-answer/internal/service/permission"
questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
"github.com/apache/incubator-answer/internal/service/revision_common"
"github.com/apache/incubator-answer/internal/service/role"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
tagcommon "github.com/apache/incubator-answer/internal/service/tag_common"
usercommon "github.com/apache/incubator-answer/internal/service/user_common"
Expand All @@ -65,6 +66,7 @@ type QuestionService struct {
questioncommon *questioncommon.QuestionCommon
userCommon *usercommon.UserCommon
userRepo usercommon.UserRepo
userRoleRelService *role.UserRoleRelService
revisionService *revision_common.RevisionService
metaService *meta.MetaService
collectionCommon *collectioncommon.CollectionCommon
Expand All @@ -83,6 +85,7 @@ func NewQuestionService(
questioncommon *questioncommon.QuestionCommon,
userCommon *usercommon.UserCommon,
userRepo usercommon.UserRepo,
userRoleRelService *role.UserRoleRelService,
revisionService *revision_common.RevisionService,
metaService *meta.MetaService,
collectionCommon *collectioncommon.CollectionCommon,
Expand All @@ -100,6 +103,7 @@ func NewQuestionService(
questioncommon: questioncommon,
userCommon: userCommon,
userRepo: userRepo,
userRoleRelService: userRoleRelService,
revisionService: revisionService,
metaService: metaService,
collectionCommon: collectionCommon,
Expand Down Expand Up @@ -1238,7 +1242,18 @@ func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID strin
func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.QuestionPageReq) (
questions []*schema.QuestionPageResp, total int64, err error) {
questions = make([]*schema.QuestionPageResp, 0)

// query by user role
showHidden := false
if req.LoginUserID != "" && req.UserIDBeSearched != "" {
showHidden = req.LoginUserID == req.UserIDBeSearched
if !showHidden {
userRole, err := qs.userRoleRelService.GetUserRole(ctx, req.LoginUserID)
if err != nil {
return nil, 0, err
}
showHidden = userRole == role.RoleAdminID || userRole == role.RoleModeratorID
}
}
// query by tag condition
var tagIDs = make([]string, 0)
if len(req.Tag) > 0 {
Expand Down Expand Up @@ -1268,7 +1283,7 @@ func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.Ques
}

questionList, total, err := qs.questionRepo.GetQuestionPage(ctx, req.Page, req.PageSize,
tagIDs, req.UserIDBeSearched, req.OrderCond, req.InDays)
tagIDs, req.UserIDBeSearched, req.OrderCond, req.InDays, showHidden)
if err != nil {
return nil, 0, err
}
Expand Down
Loading

0 comments on commit f8733c4

Please sign in to comment.