@@ -15,15 +15,6 @@ import (
15
15
)
16
16
17
17
func (s * APIV1Service ) ListAllUserStats (ctx context.Context , _ * v1pb.ListAllUserStatsRequest ) (* v1pb.ListAllUserStatsResponse , error ) {
18
- currentUser , err := s .GetCurrentUser (ctx )
19
- if err != nil {
20
- return nil , status .Errorf (codes .Internal , "failed to get user: %v" , err )
21
- }
22
- visibilities := []store.Visibility {store .Public }
23
- if currentUser != nil {
24
- visibilities = append (visibilities , store .Protected )
25
- }
26
-
27
18
workspaceMemoRelatedSetting , err := s .Store .GetWorkspaceMemoRelatedSetting (ctx )
28
19
if err != nil {
29
20
return nil , errors .Wrap (err , "failed to get workspace memo related setting" )
@@ -34,9 +25,28 @@ func (s *APIV1Service) ListAllUserStats(ctx context.Context, _ *v1pb.ListAllUser
34
25
// Exclude comments by default.
35
26
ExcludeComments : true ,
36
27
ExcludeContent : true ,
37
- VisibilityList : visibilities ,
38
28
RowStatus : & normalStatus ,
39
29
}
30
+
31
+ currentUser , err := s .GetCurrentUser (ctx )
32
+ if err != nil {
33
+ return nil , status .Errorf (codes .Internal , "failed to get user: %v" , err )
34
+ }
35
+ if currentUser == nil {
36
+ memoFind .VisibilityList = []store.Visibility {store .Public }
37
+ } else {
38
+ if memoFind .CreatorID == nil {
39
+ internalFilter := fmt .Sprintf (`creator_id == %d || visibility in ["PUBLIC", "Protected"]` , currentUser .ID )
40
+ if memoFind .Filter != nil {
41
+ filter := fmt .Sprintf ("(%s) && (%s)" , * memoFind .Filter , internalFilter )
42
+ memoFind .Filter = & filter
43
+ } else {
44
+ memoFind .Filter = & internalFilter
45
+ }
46
+ } else if * memoFind .CreatorID != currentUser .ID {
47
+ memoFind .VisibilityList = []store.Visibility {store .Public , store .Protected }
48
+ }
49
+ }
40
50
memos , err := s .Store .ListMemos (ctx , memoFind )
41
51
if err != nil {
42
52
return nil , status .Errorf (codes .Internal , "failed to list memos: %v" , err )
0 commit comments