Skip to content

Commit aa4fc12

Browse files
Conditionally apply org id filter to project lookup (#19224)
* Conditionally apply org id filter to project lookup * Add DB test
1 parent 85fb744 commit aa4fc12

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export class ProjectDBImpl extends TransactionalDBImpl<ProjectDB> implements Pro
6262

6363
public async findProjectsByCloneUrl(cloneUrl: string, organizationId?: string): Promise<Project[]> {
6464
const repo = await this.getRepo();
65-
const conditions: FindConditions<DBProject> = { cloneUrl, markedDeleted: false, teamId: organizationId };
65+
const conditions: FindConditions<DBProject> = { cloneUrl, markedDeleted: false };
66+
if (organizationId) {
67+
conditions.teamId = organizationId;
68+
}
6669
return repo.find(conditions);
6770
}
6871

components/server/src/projects/projects-service.spec.db.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("ProjectsService", async () => {
2626
let member: User;
2727
let stranger: User;
2828
let org: Organization;
29+
let anotherOrg: Organization;
2930

3031
beforeEach(async () => {
3132
container = createTestContainer();
@@ -40,12 +41,16 @@ describe("ProjectsService", async () => {
4041
// create the org
4142
const orgService = container.get(OrganizationService);
4243
org = await orgService.createOrganization(owner.id, "my-org");
44+
anotherOrg = await orgService.createOrganization(owner.id, "another-org");
4345

4446
// create and add a member
4547
member = await userDB.newUser();
4648
const invite = await orgService.getOrCreateInvite(owner.id, org.id);
4749
await orgService.joinOrganization(member.id, invite.id);
4850

51+
const anotherInvite = await orgService.getOrCreateInvite(owner.id, anotherOrg.id);
52+
await orgService.joinOrganization(member.id, anotherInvite.id);
53+
4954
// create a stranger
5055
stranger = await userDB.newUser();
5156
});
@@ -296,6 +301,30 @@ describe("ProjectsService", async () => {
296301
});
297302
});
298303

304+
it("should find projects by clone url", async () => {
305+
const ps = container.get(ProjectsService);
306+
const cloneUrl = "https://github.com/gitpod-io/gitpod.git";
307+
308+
await createTestProject(ps, org, owner, { name: "my-project", cloneUrl });
309+
await createTestProject(ps, org, owner, { name: "my-project-2", cloneUrl });
310+
311+
// Create data which should not be found
312+
await createTestProject(ps, org, owner, {
313+
name: "my-project-3",
314+
cloneUrl: "https://github.com/gitpod-io/different-repo",
315+
});
316+
await createTestProject(ps, anotherOrg, owner, {
317+
name: "my-project-4",
318+
cloneUrl,
319+
});
320+
321+
const foundProjects = await ps.findProjectsByCloneUrl(owner.id, cloneUrl, org.id);
322+
expect(foundProjects.length).to.equal(2);
323+
324+
const foundProjectsForAnyOrg = await ps.findProjectsByCloneUrl(owner.id, cloneUrl);
325+
expect(foundProjectsForAnyOrg.length).to.equal(3);
326+
});
327+
299328
async function createTestProject(
300329
ps: ProjectsService,
301330
org: Organization,

components/server/src/workspace/context-service.spec.db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ describe("ContextService", async () => {
274274
expect((ctx.context as CommitContext).revision).to.equal(gitpodEmptyContext.revision);
275275
});
276276

277-
it("should parser prebuild context", async () => {
277+
it("should parse prebuild context", async () => {
278278
const svc = container.get(ContextService);
279279
const ctx = await svc.parseContext(
280280
owner,
@@ -289,7 +289,7 @@ describe("ContextService", async () => {
289289
expect(PrebuiltWorkspaceContext.is(ctx.context)).to.equal(true);
290290
});
291291

292-
it("should parser snapshot context", async () => {
292+
it("should parse snapshot context", async () => {
293293
const svc = container.get(ContextService);
294294
const ctx = await svc.parseContext(owner, `snapshot/${snapshot.id}`, {
295295
projectId: project.id,

0 commit comments

Comments
 (0)