Skip to content

Commit 74936a3

Browse files
authored
fix: align reassignment query handlers with existing access check pattern (calcom#28876)
1 parent d251302 commit 74936a3

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

packages/trpc/server/routers/viewer/teams/managedEvents/getManagedEventUsersToReassign.handler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ensureAvailableUsers } from "@calcom/features/bookings/lib/handleNewBoo
44
import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB";
55
import type { IsFixedAwareUser } from "@calcom/features/bookings/lib/handleNewBooking/types";
66
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
7+
import { getBookingAccessService } from "@calcom/features/di/containers/BookingAccessService";
78
import { EventTypeRepository } from "@calcom/features/eventtypes/repositories/eventTypeRepository";
89
import { withSelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
910
import { ErrorCode } from "@calcom/lib/errorCodes";
@@ -12,6 +13,8 @@ import type { PrismaClient } from "@calcom/prisma";
1213

1314
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
1415

16+
import { TRPCError } from "@trpc/server";
17+
1518
import type { TGetManagedEventUsersToReassignInputSchema } from "./getManagedEventUsersToReassign.schema";
1619

1720
type GetManagedEventUsersToReassignOptions = {
@@ -74,6 +77,16 @@ export const getManagedEventUsersToReassign = async ({
7477
prefix: ["gettingManagedEventUsersToReassign", `${bookingId}`],
7578
});
7679

80+
const bookingAccessService = getBookingAccessService();
81+
const isAllowed = await bookingAccessService.doesUserIdHaveAccessToBooking({
82+
userId: user.id,
83+
bookingId,
84+
});
85+
86+
if (!isAllowed) {
87+
throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" });
88+
}
89+
7790
const bookingRepository = new BookingRepository(prisma);
7891
const eventTypeRepository = new EventTypeRepository(prisma);
7992

packages/trpc/server/routers/viewer/teams/roundRobin/getRoundRobinHostsToReasign.handler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { enrichUsersWithDelegationCredentials } from "@calcom/app-store/delegati
22
import dayjs from "@calcom/dayjs";
33
import { ensureAvailableUsers } from "@calcom/features/bookings/lib/handleNewBooking/ensureAvailableUsers";
44
import type { IsFixedAwareUser } from "@calcom/features/bookings/lib/handleNewBooking/types";
5+
import { getBookingAccessService } from "@calcom/features/di/containers/BookingAccessService";
56
import { withSelectedCalendars } from "@calcom/features/users/repositories/UserRepository";
67
import { ErrorCode } from "@calcom/lib/errorCodes";
78
import logger from "@calcom/lib/logger";
@@ -10,6 +11,8 @@ import { userSelect } from "@calcom/prisma";
1011
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
1112
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
1213

14+
import { TRPCError } from "@trpc/server";
15+
1316
import type { TGetRoundRobinHostsToReassignInputSchema } from "./getRoundRobinHostsToReasign.schema";
1417

1518
type GetRoundRobinHostsToReassignOptions = {
@@ -111,6 +114,16 @@ export const getRoundRobinHostsToReassign = async ({ ctx, input }: GetRoundRobin
111114
prefix: ["gettingRoundRobinHostsToReassign", `${bookingId}`],
112115
});
113116

117+
const bookingAccessService = getBookingAccessService();
118+
const isAllowed = await bookingAccessService.doesUserIdHaveAccessToBooking({
119+
userId: user.id,
120+
bookingId,
121+
});
122+
123+
if (!isAllowed) {
124+
throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" });
125+
}
126+
114127
const booking = await prisma.booking.findUniqueOrThrow({
115128
where: { id: bookingId },
116129
select: {

0 commit comments

Comments
 (0)