From c7accf4d6bc0ca4100000051b85f3ef1cc32becc Mon Sep 17 00:00:00 2001 From: Huiwen Date: Thu, 9 Nov 2023 16:55:42 +0000 Subject: [PATCH] fix build --- .../data/workspaces/list-workspaces-query.ts | 8 +++--- .../src/authorization/relationship-updater.ts | 2 ++ .../src/workspace/gitpod-server-impl.ts | 11 +++++--- .../workspace/workspace-service.spec.db.ts | 25 ++++++++++++++----- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/components/dashboard/src/data/workspaces/list-workspaces-query.ts b/components/dashboard/src/data/workspaces/list-workspaces-query.ts index 4b6170768dc8b5..b57c5d9bd70d50 100644 --- a/components/dashboard/src/data/workspaces/list-workspaces-query.ts +++ b/components/dashboard/src/data/workspaces/list-workspaces-query.ts @@ -4,7 +4,7 @@ * See License.AGPL.txt in the project root for license information. */ -import { WorkspaceInfo } from "@gitpod/gitpod-protocol"; +import { GetWorkspacesScope, WorkspaceInfo } from "@gitpod/gitpod-protocol"; import { useQuery } from "@tanstack/react-query"; import { getGitpodService } from "../../service/service"; import { useCurrentOrg } from "../organizations/orgs-query"; @@ -26,6 +26,7 @@ export const useListWorkspacesQuery = ({ limit }: UseListWorkspacesQueryArgs) => limit, includeWithoutProject: true, organizationId: currentOrg.data?.id, + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, }), // Additional fetch for pinned workspaces // see also: https://github.com/gitpod-io/gitpod/issues/4488 @@ -34,12 +35,13 @@ export const useListWorkspacesQuery = ({ limit }: UseListWorkspacesQueryArgs) => pinnedOnly: true, includeWithoutProject: true, organizationId: currentOrg.data?.id, + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, }), ]); // Merge both data sets into one unique (by ws id) array - const workspacesMap = new Map(infos.map((ws) => [ws.workspace.id, ws])); - const pinnedWorkspacesMap = new Map(pinned.map((ws) => [ws.workspace.id, ws])); + const workspacesMap = new Map(infos.rows.map((ws) => [ws.workspace.id, ws])); + const pinnedWorkspacesMap = new Map(pinned.rows.map((ws) => [ws.workspace.id, ws])); const workspaces = Array.from(new Map([...workspacesMap, ...pinnedWorkspacesMap]).values()); return workspaces; diff --git a/components/server/src/authorization/relationship-updater.ts b/components/server/src/authorization/relationship-updater.ts index 32f8c4f09867ca..77bdcbf020fa72 100644 --- a/components/server/src/authorization/relationship-updater.ts +++ b/components/server/src/authorization/relationship-updater.ts @@ -147,6 +147,8 @@ export class RelationshipUpdater { includeHeadless: false, includeWithoutProject: true, limit: 500, // The largest amount of workspaces is 189 today (2023-08-24) + + buildBuild: true, }); for (const ws of workspaces.rows) { diff --git a/components/server/src/workspace/gitpod-server-impl.ts b/components/server/src/workspace/gitpod-server-impl.ts index df7f615436a7c1..de19436b3485b3 100644 --- a/components/server/src/workspace/gitpod-server-impl.ts +++ b/components/server/src/workspace/gitpod-server-impl.ts @@ -72,6 +72,7 @@ import { GetDefaultWorkspaceImageResult, SearchRepositoriesParams, PaginationResponse, + GetWorkspacesScope, } from "@gitpod/gitpod-protocol"; import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositories-protocol"; import { @@ -1516,9 +1517,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { promises.push( this.getWorkspaces(ctx, { /* limit: 20 */ + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, }) .then((workspaces) => { - workspaces.forEach((ws) => { + workspaces.rows.forEach((ws) => { let repoUrl; if (CommitContext.is(ws.workspace.context)) { repoUrl = ws.workspace.context?.repository?.cloneUrl?.replace(/\.git$/, ""); @@ -1635,10 +1637,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { const fetchRecentRepos = async (): Promise => { const span = TraceContext.startSpan("getSuggestedRepositories.fetchRecentRepos", ctx); - const workspaces = await this.getWorkspaces(ctx, { organizationId }); + const workspaces = await this.getWorkspaces(ctx, { + organizationId, + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); const recentRepos: SuggestedRepositoryWithSorting[] = []; - for (const ws of workspaces) { + for (const ws of workspaces.rows) { let repoUrl; let repoName; if (CommitContext.is(ws.workspace.context)) { diff --git a/components/server/src/workspace/workspace-service.spec.db.ts b/components/server/src/workspace/workspace-service.spec.db.ts index a410aa0487325e..44804546672cfc 100644 --- a/components/server/src/workspace/workspace-service.spec.db.ts +++ b/components/server/src/workspace/workspace-service.spec.db.ts @@ -8,6 +8,7 @@ import { TypeORM } from "@gitpod/gitpod-db/lib"; import { resetDB } from "@gitpod/gitpod-db/lib/test/reset-db"; import { CommitContext, + GetWorkspacesScope, Organization, Project, User, @@ -210,13 +211,19 @@ describe("WorkspaceService", async () => { const svc = container.get(WorkspaceService); await createTestWorkspace(svc, org, owner, project); - const ownerResult = await svc.getWorkspaces(owner.id, {}); + const ownerResult = await svc.getWorkspaces(owner.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(ownerResult.total).to.equal(1); - const memberResult = await svc.getWorkspaces(member.id, {}); + const memberResult = await svc.getWorkspaces(member.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(memberResult.total).to.equal(0); - const strangerResult = await svc.getWorkspaces(stranger.id, {}); + const strangerResult = await svc.getWorkspaces(stranger.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(strangerResult.total).to.equal(0); }); @@ -226,14 +233,20 @@ describe("WorkspaceService", async () => { await svc.controlAdmission(owner.id, ws.id, "everyone"); - const ownerResult = await svc.getWorkspaces(owner.id, {}); + const ownerResult = await svc.getWorkspaces(owner.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(ownerResult.total, "owner").to.equal(1); // getWorkspaces is limited to the user's own workspaces atm - const memberResult = await svc.getWorkspaces(member.id, {}); + const memberResult = await svc.getWorkspaces(member.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(memberResult.total, "member").to.equal(0); - const strangerResult = await svc.getWorkspaces(stranger.id, {}); + const strangerResult = await svc.getWorkspaces(stranger.id, { + scope: GetWorkspacesScope.MY_WORKSPACES_IN_ORGANIZATION, + }); expect(strangerResult.total, "stranger").to.equal(0); });