Skip to content

Commit 6817583

Browse files
Yang WongLinkinStars
Yang Wong
authored andcommitted
fix issue:userprofile hide unlisted post(#661)
1 parent ec11a12 commit 6817583

File tree

6 files changed

+26
-1035
lines changed

6 files changed

+26
-1035
lines changed

cmd/wire_gen.go

+3-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/repo/question/question_repo.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (qr *questionRepo) SitemapQuestions(ctx context.Context, page, pageSize int
344344
}
345345

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

@@ -357,6 +357,9 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
357357
}
358358
if len(userID) > 0 {
359359
session.And("question.user_id = ?", userID)
360+
if !showHidden {
361+
session.And("question.show = ?", entity.QuestionShow)
362+
}
360363
} else {
361364
session.And("question.show = ?", entity.QuestionShow)
362365
}

internal/service/mock/siteinfo_repo_mock.go

-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/question_common/question.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type QuestionRepo interface {
5454
UpdateQuestion(ctx context.Context, question *entity.Question, Cols []string) (err error)
5555
GetQuestion(ctx context.Context, id string) (question *entity.Question, exist bool, err error)
5656
GetQuestionList(ctx context.Context, question *entity.Question) (questions []*entity.Question, err error)
57-
GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int) (
57+
GetQuestionPage(ctx context.Context, page, pageSize int, tagIDs []string, userID, orderCond string, inDays int, showHidden bool) (
5858
questionList []*entity.Question, total int64, err error)
5959
UpdateQuestionStatus(ctx context.Context, questionID string, status int) (err error)
6060
UpdateQuestionStatusWithOutUpdateTime(ctx context.Context, question *entity.Question) (err error)

internal/service/question_service.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/apache/incubator-answer/internal/service/permission"
4444
questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
4545
"github.com/apache/incubator-answer/internal/service/revision_common"
46+
"github.com/apache/incubator-answer/internal/service/role"
4647
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
4748
tagcommon "github.com/apache/incubator-answer/internal/service/tag_common"
4849
usercommon "github.com/apache/incubator-answer/internal/service/user_common"
@@ -65,6 +66,7 @@ type QuestionService struct {
6566
questioncommon *questioncommon.QuestionCommon
6667
userCommon *usercommon.UserCommon
6768
userRepo usercommon.UserRepo
69+
userRoleRelService *role.UserRoleRelService
6870
revisionService *revision_common.RevisionService
6971
metaService *meta.MetaService
7072
collectionCommon *collectioncommon.CollectionCommon
@@ -83,6 +85,7 @@ func NewQuestionService(
8385
questioncommon *questioncommon.QuestionCommon,
8486
userCommon *usercommon.UserCommon,
8587
userRepo usercommon.UserRepo,
88+
userRoleRelService *role.UserRoleRelService,
8689
revisionService *revision_common.RevisionService,
8790
metaService *meta.MetaService,
8891
collectionCommon *collectioncommon.CollectionCommon,
@@ -100,6 +103,7 @@ func NewQuestionService(
100103
questioncommon: questioncommon,
101104
userCommon: userCommon,
102105
userRepo: userRepo,
106+
userRoleRelService: userRoleRelService,
103107
revisionService: revisionService,
104108
metaService: metaService,
105109
collectionCommon: collectionCommon,
@@ -1238,7 +1242,18 @@ func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID strin
12381242
func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.QuestionPageReq) (
12391243
questions []*schema.QuestionPageResp, total int64, err error) {
12401244
questions = make([]*schema.QuestionPageResp, 0)
1241-
1245+
// query by user role
1246+
showHidden := false
1247+
if req.LoginUserID != "" && req.UserIDBeSearched != "" {
1248+
showHidden = req.LoginUserID == req.UserIDBeSearched
1249+
if !showHidden {
1250+
userRole, err := qs.userRoleRelService.GetUserRole(ctx, req.LoginUserID)
1251+
if err != nil {
1252+
return nil, 0, err
1253+
}
1254+
showHidden = userRole == role.RoleAdminID || userRole == role.RoleModeratorID
1255+
}
1256+
}
12421257
// query by tag condition
12431258
var tagIDs = make([]string, 0)
12441259
if len(req.Tag) > 0 {
@@ -1268,7 +1283,7 @@ func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.Ques
12681283
}
12691284

12701285
questionList, total, err := qs.questionRepo.GetQuestionPage(ctx, req.Page, req.PageSize,
1271-
tagIDs, req.UserIDBeSearched, req.OrderCond, req.InDays)
1286+
tagIDs, req.UserIDBeSearched, req.OrderCond, req.InDays, showHidden)
12721287
if err != nil {
12731288
return nil, 0, err
12741289
}

0 commit comments

Comments
 (0)