Skip to content

Commit 17d98d6

Browse files
committed
Update server and implement scopes
1 parent bacbad2 commit 17d98d6

File tree

19 files changed

+752
-1063
lines changed

19 files changed

+752
-1063
lines changed

components/dashboard/src/service/json-rpc-workspace-client.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { converter } from "./public-api";
2020
import { getGitpodService } from "./service";
2121
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";
2222
import { generateAsyncGenerator } from "@gitpod/gitpod-protocol/lib/generate-async-generator";
23-
import { WorkspaceInstance } from "@gitpod/gitpod-protocol";
23+
import { GetWorkspacesScope, WorkspaceInstance } from "@gitpod/gitpod-protocol";
2424

2525
export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceService> {
2626
async getWorkspace(request: PartialMessage<GetWorkspaceRequest>): Promise<GetWorkspaceResponse> {
@@ -90,24 +90,28 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
9090
_options?: CallOptions,
9191
): Promise<ListWorkspacesResponse> {
9292
request.scope = request.scope ?? ListWorkspacesRequest_Scope.MY_WORKSPACES_IN_ORGANIZATION;
93-
if (
94-
request.scope === ListWorkspacesRequest_Scope.MY_WORKSPACES_IN_ORGANIZATION ||
95-
request.scope === ListWorkspacesRequest_Scope.ALL_WORKSPACES_IN_ORGANIZATION
96-
) {
97-
throw new ConnectError("organization_id is required", Code.InvalidArgument);
93+
let getWorkspacesScope: GetWorkspacesScope = GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION;
94+
if (request.scope === ListWorkspacesRequest_Scope.ALL_WORKSPACES_IN_INSTALLATION) {
95+
getWorkspacesScope = GetWorkspacesScope.ALL_WORKSPACES_IN_INSTALLATION;
96+
} else if (request.scope === ListWorkspacesRequest_Scope.ALL_WORKSPACES_IN_ORGANIZATION) {
97+
getWorkspacesScope = GetWorkspacesScope.ALL_WORKSPACES_IN_ORGANIZATION;
98+
} else if (request.scope === ListWorkspacesRequest_Scope.MY_WORKSPACES_IN_ORGANIZATION) {
99+
getWorkspacesScope = GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION;
98100
}
99101
const server = getGitpodService().server;
100102
const pageSize = request.pagination?.pageSize || 100;
101-
const workspaces = await server.getWorkspaces({
103+
const results = await server.getWorkspaces({
102104
organizationId: request.organizationId,
103-
pinnedOnly: request.pinned === true ? true : undefined,
105+
pinnedOnly: request.pinned,
104106
limit: pageSize,
105107
offset: (request.pagination?.page ?? 0) * pageSize,
108+
searchString: request.searchTerm,
109+
scope: getWorkspacesScope,
106110
});
107111
const response = new ListWorkspacesResponse();
108-
response.workspaces = workspaces.map((info) => converter.toWorkspace(info));
112+
response.workspaces = results.rows.map((info) => converter.toWorkspace(info));
109113
response.pagination = new PaginationResponse();
110-
response.pagination.total = workspaces.length;
114+
response.pagination.total = results.total;
111115
return response;
112116
}
113117
}

components/gitpod-db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": "yarn db-test",
1313
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput",
1414
"db-test": "r(){ . $(leeway run components/gitpod-db:db-test-env); yarn db-test-run; };r",
15-
"db-test-run": "mocha '**/*.spec.db.ts' --exclude './node_modules/**' --exit",
15+
"db-test-run": "mocha '**/workspace-db.spec.db.ts' --exclude './node_modules/**' --exit",
1616
"wait-for-db": "node ./lib/wait-for-db.js",
1717
"typeorm": "typeorm -f lib/typeorm/ormconfig",
1818
"migrate-migrations": "node ./lib/migrate-migrations.js",

components/gitpod-db/src/typeorm/workspace-db-impl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
210210
"wsiRunning",
211211
"ws.id = wsiRunning.workspaceId",
212212
)
213-
.where("ws.ownerId = :userId", { userId: options.userId })
214-
.andWhere("ws.softDeletedTime = ''") // enables usage of: ind_softDeletion
213+
.where("ws.softDeletedTime = ''") // enables usage of: ind_softDeletion
215214
.andWhere("ws.softDeleted IS NULL")
216215
.andWhere("ws.deleted != TRUE")
217216
.orderBy("wsiRunning.workspaceId", "DESC")
218217
.addOrderBy("GREATEST(ws.creationTime, wsi.creationTime, wsi.startedTime, wsi.stoppedTime)", "DESC")
218+
.offset(options.offset || 0)
219219
.limit(options.limit || 10);
220+
if (options.userId) {
221+
qb.andWhere("ws.ownerId = :userId", { userId: options.userId });
222+
}
220223
if (options.searchString) {
221224
qb.andWhere("ws.description LIKE :searchString", { searchString: `%${options.searchString}%` });
222225
}

0 commit comments

Comments
 (0)