Skip to content

Conditionally apply org id filter to project lookup #19224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/gitpod-db/src/typeorm/project-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export class ProjectDBImpl extends TransactionalDBImpl<ProjectDB> implements Pro

public async findProjectsByCloneUrl(cloneUrl: string, organizationId?: string): Promise<Project[]> {
const repo = await this.getRepo();
const conditions: FindConditions<DBProject> = { cloneUrl, markedDeleted: false, teamId: organizationId };
const conditions: FindConditions<DBProject> = { cloneUrl, markedDeleted: false };
if (organizationId) {
conditions.teamId = organizationId;
}
return repo.find(conditions);
}

Expand Down
29 changes: 29 additions & 0 deletions components/server/src/projects/projects-service.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("ProjectsService", async () => {
let member: User;
let stranger: User;
let org: Organization;
let anotherOrg: Organization;

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

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

const anotherInvite = await orgService.getOrCreateInvite(owner.id, anotherOrg.id);
await orgService.joinOrganization(member.id, anotherInvite.id);

// create a stranger
stranger = await userDB.newUser();
});
Expand Down Expand Up @@ -296,6 +301,30 @@ describe("ProjectsService", async () => {
});
});

it("should find projects by clone url", async () => {
const ps = container.get(ProjectsService);
const cloneUrl = "https://github.com/gitpod-io/gitpod.git";

await createTestProject(ps, org, owner, { name: "my-project", cloneUrl });
await createTestProject(ps, org, owner, { name: "my-project-2", cloneUrl });

// Create data which should not be found
await createTestProject(ps, org, owner, {
name: "my-project-3",
cloneUrl: "https://github.com/gitpod-io/different-repo",
});
await createTestProject(ps, anotherOrg, owner, {
name: "my-project-4",
cloneUrl,
});

const foundProjects = await ps.findProjectsByCloneUrl(owner.id, cloneUrl, org.id);
expect(foundProjects.length).to.equal(2);

const foundProjectsForAnyOrg = await ps.findProjectsByCloneUrl(owner.id, cloneUrl);
expect(foundProjectsForAnyOrg.length).to.equal(3);
});

async function createTestProject(
ps: ProjectsService,
org: Organization,
Expand Down
4 changes: 2 additions & 2 deletions components/server/src/workspace/context-service.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe("ContextService", async () => {
expect((ctx.context as CommitContext).revision).to.equal(gitpodEmptyContext.revision);
});

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

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