Skip to content

Commit 69e0de5

Browse files
authored
feat(server): change project filter [VIZ-2160] (#1770)
1 parent 24098e6 commit 69e0de5

File tree

10 files changed

+225
-238
lines changed

10 files changed

+225
-238
lines changed

server/e2e/common.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func init() {
6464
mongotest.Env = "REEARTH_DB"
6565
}
6666

67-
func initRepos(t *testing.T, useMongo bool, seeder Seeder) (repos *repo.Container, file gateway.File) {
68-
ctx := context.Background()
67+
func initRepos(t *testing.T, useMongo bool, seeder Seeder) (repos *repo.Container, file gateway.File, ctx context.Context) {
68+
ctx = context.Background()
6969

7070
if useMongo {
7171
db := mongotest.Connect(t)(t)
@@ -84,7 +84,7 @@ func initRepos(t *testing.T, useMongo bool, seeder Seeder) (repos *repo.Containe
8484
}
8585
}
8686

87-
return repos, file
87+
return repos, file, ctx
8888
}
8989

9090
func initGateway() *gateway.Container {
@@ -173,17 +173,23 @@ func StartGQLServerWithRepos(t *testing.T, cfg *config.Config, repos *repo.Conta
173173
}
174174

175175
func StartGQLServerAndRepos(t *testing.T, seeder Seeder) (*httpexpect.Expect, *accountrepo.Container) {
176-
repos, _ := initRepos(t, true, seeder)
176+
repos, _, _ := initRepos(t, true, seeder)
177177
e, _, _ := StartGQLServerWithRepos(t, disabledAuthConfig, repos)
178178
return e, repos.AccountRepos()
179179
}
180180

181181
func startServer(t *testing.T, cfg *config.Config, useMongo bool, seeder Seeder) (*httpexpect.Expect, *repo.Container, *gateway.Container) {
182-
repos, _ := initRepos(t, useMongo, seeder)
182+
repos, _, _ := initRepos(t, useMongo, seeder)
183183
e, gateways, _ := StartGQLServerWithRepos(t, cfg, repos)
184184
return e, repos, gateways
185185
}
186186

187+
func startServerWithCtx(t *testing.T, cfg *config.Config, useMongo bool, seeder Seeder) (*httpexpect.Expect, *repo.Container, *gateway.Container, context.Context) {
188+
repos, _, ctx := initRepos(t, useMongo, seeder)
189+
e, gateways, _ := StartGQLServerWithRepos(t, cfg, repos)
190+
return e, repos, gateways, ctx
191+
}
192+
187193
func ServerAndRepos(t *testing.T, seeder Seeder) (*httpexpect.Expect, *repo.Container, *gateway.Container) {
188194
return startServer(t, disabledAuthConfig, true, seeder)
189195
}
@@ -192,6 +198,10 @@ func GRPCServer(t *testing.T, seeder Seeder) (*httpexpect.Expect, *repo.Containe
192198
return startServer(t, internalApiConfig, true, seeder)
193199
}
194200

201+
func GRPCServeWithCtx(t *testing.T, seeder Seeder) (*httpexpect.Expect, *repo.Container, *gateway.Container, context.Context) {
202+
return startServerWithCtx(t, internalApiConfig, true, seeder)
203+
}
204+
195205
func Server(t *testing.T, seeder Seeder) *httpexpect.Expect {
196206
e, _, _ := startServer(t, disabledAuthConfig, true, seeder)
197207
return e

server/e2e/proto_project_sort_pagination_test.go

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ import (
1616
"github.com/reearth/reearth/server/pkg/storytelling"
1717
"github.com/reearth/reearth/server/pkg/visualizer"
1818
"github.com/reearth/reearthx/account/accountdomain"
19+
"github.com/reearth/reearthx/account/accountdomain/workspace"
1920
"github.com/stretchr/testify/assert"
2021
)
2122

22-
// go test -v -run TestInternalAPI_GetProjectList ./e2e/...
23+
// go test -v -run TestInternalAPI_GetProjectList_Owner ./e2e/...
2324

24-
func TestInternalAPI_GetProjectList(t *testing.T) {
25-
_, r, _ := GRPCServer(t, baseSeeder)
25+
func TestInternalAPI_GetProjectList_Owner(t *testing.T) {
26+
_, r, _, _ := GRPCServeWithCtx(t, baseSeeder)
2627

2728
testDataCount := 20
2829
testWorkspace2 := wID2.String()
2930
limit := 5
3031

31-
// user2 call api
32+
// user2(Owner) call api
3233
runTestWithUser(t, uID2.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
3334

35+
//####################################
36+
// Add TestData for user2 workspace
3437
SetupTestProjectDatas(t, ctx, r, wID2, testDataCount)
38+
//####################################
3539

3640
// ASC UpdateAt
3741
checkGetProjectsASC(t, client, ctx, true,
@@ -92,7 +96,32 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
9296

9397
})
9498

95-
// user1 call api
99+
}
100+
101+
// go test -v -run TestInternalAPI_GetProjectList_Member ./e2e/...
102+
func TestInternalAPI_GetProjectList_Member(t *testing.T) {
103+
_, r, _, ctx := GRPCServeWithCtx(t, baseSeeder)
104+
105+
testDataCount := 20
106+
testWorkspace2 := wID2.String()
107+
limit := 5
108+
109+
// user2(Owner) call api
110+
runTestWithUser(t, uID2.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
111+
112+
//####################################
113+
// Add TestData for user2 workspace
114+
SetupTestProjectDatas(t, ctx, r, wID2, testDataCount)
115+
//####################################
116+
117+
})
118+
119+
// add user1 to workspace2(user2)
120+
user1, err := r.User.FindByID(ctx, uID)
121+
assert.Nil(t, err)
122+
assert.Nil(t, JoinMembers(ctx, r, wID2, user1, workspace.RoleReader, uID2))
123+
124+
// user1(Member) call api
96125
runTestWithUser(t, uID.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
97126

98127
// ASC UpdateAt
@@ -103,7 +132,89 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
103132
Direction: pb.SortDirection_ASC,
104133
},
105134
limit,
106-
testDataCount, // public and not deleted only
135+
testDataCount*4, // all project
136+
)
137+
138+
// ASC Name
139+
checkGetProjectsASC(t, client, ctx, true,
140+
&testWorkspace2, // user2 workspace
141+
&pb.ProjectSort{
142+
Field: pb.ProjectSortField_NAME,
143+
Direction: pb.SortDirection_ASC,
144+
},
145+
limit,
146+
testDataCount*4, // all project
147+
)
148+
149+
// DESC UpdateAt
150+
checkGetProjectsDESC(t, client, ctx, true,
151+
&testWorkspace2, // user2 workspace
152+
&pb.ProjectSort{
153+
Field: pb.ProjectSortField_UPDATEDAT,
154+
Direction: pb.SortDirection_DESC,
155+
},
156+
limit,
157+
testDataCount*4, // all project
158+
)
159+
160+
// DESC Name
161+
checkGetProjectsDESC(t, client, ctx, true,
162+
&testWorkspace2, // user2 workspace
163+
&pb.ProjectSort{
164+
Field: pb.ProjectSortField_NAME,
165+
Direction: pb.SortDirection_DESC,
166+
},
167+
limit,
168+
testDataCount*4, // all project
169+
)
170+
171+
// keyword search
172+
keyword := "2"
173+
checkGetProjectsASCWithKeyword(t, client, ctx, true,
174+
&testWorkspace2, // user2 workspace
175+
&pb.ProjectSort{
176+
Field: pb.ProjectSortField_UPDATEDAT,
177+
Direction: pb.SortDirection_ASC,
178+
},
179+
&keyword,
180+
limit,
181+
26,
182+
)
183+
184+
})
185+
186+
}
187+
188+
// go test -v -run TestInternalAPI_GetProjectList_Anonymous ./e2e/...
189+
func TestInternalAPI_GetProjectList_Anonymous(t *testing.T) {
190+
_, r, _, _ := GRPCServeWithCtx(t, baseSeeder)
191+
192+
testDataCount := 20
193+
testWorkspace2 := wID2.String()
194+
limit := 5
195+
196+
// user2(Owner) call api
197+
runTestWithUser(t, uID2.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
198+
199+
//####################################
200+
// Add TestData for user2 workspace
201+
SetupTestProjectDatas(t, ctx, r, wID2, testDataCount)
202+
//####################################
203+
204+
})
205+
206+
// user3(Anonymous) call api
207+
runTestWithUser(t, uID3.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
208+
209+
// ASC UpdateAt
210+
checkGetProjectsASC(t, client, ctx, true,
211+
&testWorkspace2, // user2 workspace
212+
&pb.ProjectSort{
213+
Field: pb.ProjectSortField_UPDATEDAT,
214+
Direction: pb.SortDirection_ASC,
215+
},
216+
limit,
217+
testDataCount*2, // public project only
107218
)
108219

109220
// ASC Name
@@ -114,7 +225,7 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
114225
Direction: pb.SortDirection_ASC,
115226
},
116227
limit,
117-
testDataCount, // public and not deleted only
228+
testDataCount*2, // public project only
118229
)
119230

120231
// DESC UpdateAt
@@ -125,7 +236,7 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
125236
Direction: pb.SortDirection_DESC,
126237
},
127238
limit,
128-
testDataCount, // public and not deleted only
239+
testDataCount*2, // public project only
129240
)
130241

131242
// DESC Name
@@ -136,7 +247,7 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
136247
Direction: pb.SortDirection_DESC,
137248
},
138249
limit,
139-
testDataCount, // public and not deleted only
250+
testDataCount*2, // public project only
140251
)
141252

142253
// keyword search
@@ -149,7 +260,7 @@ func TestInternalAPI_GetProjectList(t *testing.T) {
149260
},
150261
&keyword,
151262
limit,
152-
20,
263+
22,
153264
)
154265

155266
})

server/e2e/proto_project_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
)
2525

2626
// export REEARTH_DB=mongodb://localhost
27-
// go test -v -run TestInternalAPI ./e2e/...
27+
// go test -v -run TestInternalAPI_Basic ./e2e/...
2828

29-
func TestInternalAPI(t *testing.T) {
29+
func TestInternalAPI_Basic(t *testing.T) {
3030
_, r, _ := GRPCServer(t, baseSeeder)
3131
testWorkspace := wID.String()
3232

@@ -100,22 +100,19 @@ func TestInternalAPI(t *testing.T) {
100100

101101
// user2 call api
102102
runTestWithUser(t, uID2.String(), func(client pb.ReEarthVisualizerClient, ctx context.Context) {
103-
// get list size 1
104103
res3, err := client.GetProjectList(ctx, &pb.GetProjectListRequest{
105104
Authenticated: false,
106105
WorkspaceId: &testWorkspace,
107106
})
108107
assert.Nil(t, err)
109-
assert.Equal(t, 1, len(res3.Projects))
110-
// 3: creante public => public delete => false
108+
assert.Equal(t, 2, len(res3.Projects))
111109

112-
// Authenticated => get list size 1
113110
res4, err := client.GetProjectList(ctx, &pb.GetProjectListRequest{
114111
Authenticated: true,
115112
WorkspaceId: &testWorkspace,
116113
})
117114
assert.Nil(t, err)
118-
assert.Equal(t, 1, len(res4.Projects))
115+
assert.Equal(t, 2, len(res4.Projects))
119116

120117
})
121118

@@ -127,10 +124,7 @@ func TestInternalAPI(t *testing.T) {
127124
WorkspaceId: &testWorkspace,
128125
})
129126
assert.Nil(t, err)
130-
assert.Equal(t, 1, len(res3.Projects))
131-
132-
// 2: creante public => public delete => false
133-
// 3: creante private => private delete => false
127+
assert.Equal(t, 4, len(res3.Projects))
134128
})
135129

136130
}

server/internal/adapter/internalapi/server.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ func (s server) GetProjectList(ctx context.Context, req *pb.GetProjectListReques
5252
}
5353
}
5454

55+
var err error
5556
if req.WorkspaceId == nil {
56-
var err error
57+
5758
res, info, err = uc.Project.FindVisibilityByUser(
58-
ctx, adapter.User(ctx),
59+
ctx,
60+
adapter.User(ctx),
5961
req.Authenticated,
6062
op,
6163
req.Keyword,
@@ -79,11 +81,17 @@ func (s server) GetProjectList(ctx context.Context, req *pb.GetProjectListReques
7981
param.Limit = req.Pagination.Limit
8082
param.Offset = req.Pagination.Offset
8183
}
84+
8285
res, info, err = uc.Project.FindVisibilityByWorkspace(
83-
ctx, wId, req.Authenticated, op, req.Keyword, sort, pagination,
86+
ctx,
87+
wId,
88+
req.Authenticated,
89+
op,
90+
req.Keyword,
91+
sort,
92+
pagination,
8493
param,
8594
)
86-
8795
if err != nil {
8896
return nil, err
8997
}
@@ -99,6 +107,7 @@ func (s server) GetProjectList(ctx context.Context, req *pb.GetProjectListReques
99107
Projects: projects,
100108
PageInfo: internalapimodel.ToProjectPageInfo(info),
101109
}, nil
110+
102111
}
103112

104113
func (s server) GetProject(ctx context.Context, req *pb.GetProjectRequest) (*pb.GetProjectResponse, error) {

server/internal/infrastructure/memory/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (r *Project) FindByWorkspace(ctx context.Context, id accountdomain.Workspac
8484
), nil
8585
}
8686

87-
func (r *Project) FindByWorkspaces(ctx context.Context, authenticated bool, pFilter repo.ProjectFilter, owningWorkspaces accountdomain.WorkspaceIDList, wList accountdomain.WorkspaceIDList) ([]*project.Project, *usecasex.PageInfo, error) {
87+
func (r *Project) FindByWorkspaces(ctx context.Context, authenticated bool, pFilter repo.ProjectFilter, ownedWorkspaces []string, memberWorkspaces []string, targetWsList []string) ([]*project.Project, *usecasex.PageInfo, error) {
8888
return nil, nil, nil
8989
}
9090

0 commit comments

Comments
 (0)