feat: Schedule restriction and booker timezone (#21452)

* init migration and fix name for team event availability toggle

* show and save restriction schedule

* better naming around

* fix loading stored restricted schedule instead of default

* add the booker timezone checkbox in the form

* restriction schedule application babbbyyyy

* remove logs

* test

* typefix

* fix

* fix??

* fix???

* ---

* typefix

* functional fix

* restrictionschedule logic --1

* timezone adjustment for regular constraint

* noice

* test suite for restrictionSchedule

* auth restrictionschedule for eventtype

* remove unnecessary comments

* index

* type fix

* add concurrent

* resolve change request

* fix unauth erro

* type fix

* schedule select extracted from select

* revert

* fix auth vulnerabililty

* fix e22

* chore: hide restriction schedule on platform

* init review feedback resolutions

* fixes

* fix type

* multiple windows of recurring rule-same day

* team feature flag

* fix type err

* fix type

* improvements

* fix test

* improve

* fix error propagation

* fix unused var lint

* cleanup and using buildDateRanges

* travel schedule inclusion

* address comment

---------

Co-authored-by: supalarry <[email protected]>
This commit is contained in:
Syed Ali Shahbazandsupalarry authored and GitHub committed 2025-06-19 14:08:51 +01:00
1 parent 3bea03f4b1
commit e160a4add0
28 files changed
+1307 -73

No files matched your search

+28 -3
View File
@@ -1,6 +1,6 @@
import { Prisma } from "@calcom/prisma/client";
import type { Prisma } from "@calcom/prisma/client";
export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
export const eventTypeSelect = {
id: true,
teamId: true,
schedulingType: true,
@@ -71,4 +71,29 @@ export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
maxLeadThreshold: true,
useEventLevelSelectedCalendars: true,
customReplyToEmail: true,
});
restrictionScheduleId: true,
useBookerTimezone: true,
instantMeetingSchedule: {
select: {
id: true,
name: true,
},
},
} satisfies Prisma.EventTypeSelect;
// Create a separate select for schedule-related fields
export const eventTypeScheduleSelect = {
...eventTypeSelect,
schedule: {
select: {
id: true,
name: true,
},
},
restrictionSchedule: {
select: {
id: true,
name: true,
},
},
} satisfies Prisma.EventTypeSelect;
@@ -592,6 +592,8 @@ export class EventTypeRepository {
},
},
},
restrictionScheduleId: true,
useBookerTimezone: true,
users: {
select: userSelect,
},
@@ -608,6 +610,12 @@ export class EventTypeRepository {
name: true,
},
},
restrictionSchedule: {
select: {
id: true,
name: true,
},
},
hosts: {
select: {
isFixed: true,
@@ -842,6 +850,8 @@ export class EventTypeRepository {
maxLeadThreshold: true,
includeNoShowInRRCalculation: true,
useEventLevelSelectedCalendars: true,
restrictionScheduleId: true,
useBookerTimezone: true,
team: {
select: {
id: true,
+32 -1
View File
@@ -1,4 +1,4 @@
import { availabilityUserSelect, prisma, type PrismaTransaction } from "@calcom/prisma";
import { availabilityUserSelect, prisma, type PrismaTransaction, type PrismaClient } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/client";
import { Prisma } from "@calcom/prisma/client";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
@@ -70,6 +70,37 @@ const getWhereForfindAllByUpId = async (upId: string, where?: Prisma.MembershipW
};
export class MembershipRepository {
constructor(private readonly prismaClient: PrismaClient = prisma) {}
async hasMembership({ userId, teamId }: { userId: number; teamId: number }): Promise<boolean> {
const membership = await this.prismaClient.membership.findFirst({
where: {
userId,
teamId,
accepted: true,
},
select: {
id: true,
},
});
return !!membership;
}
async listAcceptedTeamMemberIds({ teamId }: { teamId: number }): Promise<number[]> {
const memberships =
(await this.prismaClient.membership.findMany({
where: {
teamId,
accepted: true,
},
select: {
userId: true,
},
})) || [];
const teamMemberIds = memberships.map((membership) => membership.userId);
return teamMemberIds;
}
static async create(data: IMembership) {
return await prisma.membership.create({
data: {
@@ -1,3 +1,4 @@
import type { PrismaClient } from "@calcom/prisma";
import prisma from "@calcom/prisma";
import { getDefaultScheduleId } from "@calcom/trpc/server/routers/viewer/availability/util";
@@ -13,6 +14,56 @@ export type FindDetailedScheduleByIdReturnType = Awaited<
>;
export class ScheduleRepository {
// when instantiating, prismaClient injection is required
constructor(private prismaClient: PrismaClient) {}
async findScheduleByIdForBuildDateRanges({ scheduleId }: { scheduleId: number }) {
const schedule = await this.prismaClient.schedule.findUnique({
where: { id: scheduleId },
select: {
id: true,
timeZone: true,
userId: true,
availability: {
select: {
days: true,
startTime: true,
endTime: true,
date: true,
},
},
user: {
select: {
id: true,
defaultScheduleId: true,
travelSchedules: {
select: {
id: true,
timeZone: true,
startDate: true,
endDate: true,
},
},
},
},
},
});
return schedule;
}
async findScheduleByIdForOwnershipCheck({ scheduleId }: { scheduleId: number }) {
const schedule = await this.prismaClient.schedule.findUnique({
where: {
id: scheduleId,
},
select: {
userId: true,
},
});
return schedule;
}
static async findScheduleById({ id }: { id: number }) {
const schedule = await prisma.schedule.findUnique({
where: {