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:
1 parent
3bea03f4b1
commit
e160a4add0
28 files changed
+1307
-73
No files matched your search
@@ -135,6 +135,8 @@ const commons = {
|
||||
rrTimestampBasis: null,
|
||||
interfaceLanguage: null,
|
||||
customReplyToEmail: null,
|
||||
restrictionScheduleId: null,
|
||||
useBookerTimezone: false,
|
||||
profileId: null,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
canSendCalVideoTranscriptionEmails: false,
|
||||
|
||||
@@ -20,4 +20,6 @@ export enum ErrorCode {
|
||||
BookingConflict = "booking_conflict_error",
|
||||
BookerLimitExceeded = "booker_limit_exceeded_error",
|
||||
BookerLimitExceededReschedule = "booker_limit_exceeded_error_reschedule",
|
||||
BookingNotAllowedByRestrictionSchedule = "booking_not_allowed_by_restriction_schedule_error",
|
||||
RestrictionScheduleNotFound = "restriction_schedule_not_found_error",
|
||||
}
|
||||
@@ -112,6 +112,9 @@ export const getEventTypeById = async ({
|
||||
rawEventType.schedule?.id ||
|
||||
(!rawEventType.team ? rawEventType.users[0]?.defaultScheduleId : null) ||
|
||||
null,
|
||||
restrictionScheduleId: rawEventType.restrictionScheduleId || null,
|
||||
restrictionScheduleName: rawEventType.restrictionSchedule?.name || null,
|
||||
useBookerTimezone: rawEventType.useBookerTimezone || false,
|
||||
instantMeetingSchedule: rawEventType.instantMeetingSchedule?.id || null,
|
||||
scheduleName: rawEventType.schedule?.name || null,
|
||||
recurringEvent: parseRecurringEvent(restEventType.recurringEvent),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
|
||||
/**
|
||||
* Checks if the restriction schedule feature is enabled for a team
|
||||
* @param teamId - The team ID to check
|
||||
* @returns Promise<boolean> - True if the feature is enabled, false otherwise
|
||||
*/
|
||||
export async function isRestrictionScheduleEnabled(teamId?: number): Promise<boolean> {
|
||||
if (!teamId) {
|
||||
return false; // Personal events don't have restriction schedules
|
||||
}
|
||||
|
||||
const featureRepo = new FeaturesRepository();
|
||||
return await featureRepo.checkIfTeamHasFeature(teamId, "restriction-schedule");
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -157,6 +157,8 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
|
||||
allowReschedulingPastBookings: false,
|
||||
hideOrganizerEmail: false,
|
||||
customReplyToEmail: null,
|
||||
restrictionScheduleId: null,
|
||||
useBookerTimezone: false,
|
||||
...eventType,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user