Skip to content

Commit 9c6e331

Browse files
fix: validate hosts belong to team in managed event type create/update (calcom#26952)
* fix: validate hosts belong to team in managed event type create/update Co-Authored-By: morgan@cal.com <morgan@cal.com> * test: add e2e tests for managed event type host validation Co-Authored-By: morgan@cal.com <morgan@cal.com> * fix: move update test after get team event-types test to fix ordering Co-Authored-By: morgan@cal.com <morgan@cal.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 1f28504 commit 9c6e331

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

apps/api/v2/src/modules/organizations/event-types/services/input.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export class InputOrganizationsEventTypesService {
316316
}
317317

318318
if (inputEventType.hosts) {
319+
await this.validateHosts(teamId, inputEventType.hosts);
319320
return inputEventType.hosts.map((host) => host.userId);
320321
}
321322

@@ -354,6 +355,7 @@ export class InputOrganizationsEventTypesService {
354355
}
355356

356357
if (inputEventType.hosts) {
358+
await this.validateHosts(teamId, inputEventType.hosts);
357359
return inputEventType.hosts.map((host) => host.userId);
358360
}
359361

apps/api/v2/src/modules/teams/event-types/controllers/teams-event-types.controller.e2e-spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,33 @@ describe("Organizations Event Types Endpoints", () => {
205205
return request(app.getHttpServer()).post(`/v2/teams/${team.id}/event-types`).send(body).expect(404);
206206
});
207207

208+
it("should not be able to create managed event-type for user outside team", async () => {
209+
const userId = falseTestUser.id;
210+
211+
const body: CreateTeamEventTypeInput_2024_06_14 = {
212+
title: `managed-outside-team-${randomString()}`,
213+
slug: `managed-outside-team-${randomString()}`,
214+
description: "Managed event type with non-team member.",
215+
lengthInMinutes: 60,
216+
locations: [
217+
{
218+
type: "integration",
219+
integration: "cal-video",
220+
},
221+
],
222+
schedulingType: "MANAGED",
223+
hosts: [
224+
{
225+
userId,
226+
mandatory: true,
227+
priority: "high",
228+
},
229+
],
230+
};
231+
232+
return request(app.getHttpServer()).post(`/v2/teams/${team.id}/event-types`).send(body).expect(404);
233+
});
234+
208235
it("should not be able to create phone-only event type", async () => {
209236
const body: CreateTeamEventTypeInput_2024_06_14 = {
210237
title: "Phone coding consultation",
@@ -564,6 +591,25 @@ describe("Organizations Event Types Endpoints", () => {
564591
});
565592
});
566593

594+
it("should not be able to update managed event-type with user outside team", async () => {
595+
await ensureManagedEventType();
596+
597+
const body: UpdateTeamEventTypeInput_2024_06_14 = {
598+
hosts: [
599+
{
600+
userId: falseTestUser.id,
601+
mandatory: true,
602+
priority: "high",
603+
},
604+
],
605+
};
606+
607+
return request(app.getHttpServer())
608+
.patch(`/v2/teams/${team.id}/event-types/${managedEventType?.id}`)
609+
.send(body)
610+
.expect(404);
611+
});
612+
567613
it("should not be able to update non existing event-type", async () => {
568614
const body: UpdateTeamEventTypeInput_2024_06_14 = {
569615
title: "Clean code consultation",

0 commit comments

Comments
 (0)