@@ -43,6 +43,7 @@ import (
43
43
"github.com/apache/incubator-answer/internal/service/permission"
44
44
questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
45
45
"github.com/apache/incubator-answer/internal/service/revision_common"
46
+ "github.com/apache/incubator-answer/internal/service/role"
46
47
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
47
48
tagcommon "github.com/apache/incubator-answer/internal/service/tag_common"
48
49
usercommon "github.com/apache/incubator-answer/internal/service/user_common"
@@ -65,6 +66,7 @@ type QuestionService struct {
65
66
questioncommon * questioncommon.QuestionCommon
66
67
userCommon * usercommon.UserCommon
67
68
userRepo usercommon.UserRepo
69
+ userRoleRelService * role.UserRoleRelService
68
70
revisionService * revision_common.RevisionService
69
71
metaService * meta.MetaService
70
72
collectionCommon * collectioncommon.CollectionCommon
@@ -83,6 +85,7 @@ func NewQuestionService(
83
85
questioncommon * questioncommon.QuestionCommon ,
84
86
userCommon * usercommon.UserCommon ,
85
87
userRepo usercommon.UserRepo ,
88
+ userRoleRelService * role.UserRoleRelService ,
86
89
revisionService * revision_common.RevisionService ,
87
90
metaService * meta.MetaService ,
88
91
collectionCommon * collectioncommon.CollectionCommon ,
@@ -100,6 +103,7 @@ func NewQuestionService(
100
103
questioncommon : questioncommon ,
101
104
userCommon : userCommon ,
102
105
userRepo : userRepo ,
106
+ userRoleRelService : userRoleRelService ,
103
107
revisionService : revisionService ,
104
108
metaService : metaService ,
105
109
collectionCommon : collectionCommon ,
@@ -1238,7 +1242,18 @@ func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID strin
1238
1242
func (qs * QuestionService ) GetQuestionPage (ctx context.Context , req * schema.QuestionPageReq ) (
1239
1243
questions []* schema.QuestionPageResp , total int64 , err error ) {
1240
1244
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
+ }
1242
1257
// query by tag condition
1243
1258
var tagIDs = make ([]string , 0 )
1244
1259
if len (req .Tag ) > 0 {
@@ -1268,7 +1283,7 @@ func (qs *QuestionService) GetQuestionPage(ctx context.Context, req *schema.Ques
1268
1283
}
1269
1284
1270
1285
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 )
1272
1287
if err != nil {
1273
1288
return nil , 0 , err
1274
1289
}
0 commit comments