Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Nov 9, 2023
1 parent 17d98d6 commit c7accf4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions components/server/src/authorization/relationship-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
GetDefaultWorkspaceImageResult,
SearchRepositoriesParams,
PaginationResponse,
GetWorkspacesScope,
} from "@gitpod/gitpod-protocol";
import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositories-protocol";
import {
Expand Down Expand Up @@ -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$/, "");
Expand Down Expand Up @@ -1635,10 +1637,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const fetchRecentRepos = async (): Promise<SuggestedRepositoryWithSorting[]> => {
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)) {
Expand Down
25 changes: 19 additions & 6 deletions components/server/src/workspace/workspace-service.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand Down

0 comments on commit c7accf4

Please sign in to comment.