feat: add setting to automatic start recording (#21853)

* feat: disable transcription setting in cal video

* feat: add enable automatic recording feature

* chore: only when organizer joins

* chore: update name of variable

* fix: improvements

* chore: improvements

* chore: add badge

* refactor: cal video premium

* tests: add tests for cal video

* fix: use isOrganizer

* Simplify type to remove 'as SessionUser' from new code

---------

Co-authored-by: Benny Joo <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-15 16:54:23 +01:00
1 parent 8ee7b12c2b
commit 10bf982028
19 files changed
+857 -197

No files matched your search

@@ -25,6 +25,7 @@ import ServerTrans from "@calcom/lib/components/ServerTrans";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import classNames from "@calcom/ui/classNames";
import { UpgradeTeamsBadge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { TextField } from "@calcom/ui/components/form";
import { SettingsToggle } from "@calcom/ui/components/form";
@@ -355,6 +356,7 @@ const Locations: React.FC<LocationsProps> = ({
labelClassName="text-sm leading-6 whitespace-normal break-words"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
@@ -370,11 +372,30 @@ const Locations: React.FC<LocationsProps> = ({
labelClassName="text-sm leading-6 whitespace-normal break-words"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
/>
{!isPlatform && (
<Controller
name="calVideoSettings.enableAutomaticRecordingForOrganizer"
defaultValue={!!eventType.calVideoSettings?.enableAutomaticRecordingForOrganizer}
render={({ field: { onChange, value } }) => {
return (
<SettingsToggle
title={t("enable_automatic_recording")}
labelClassName="text-sm"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
/>
)}
<Controller
name="calVideoSettings.enableAutomaticTranscription"
defaultValue={!!eventType.calVideoSettings?.enableAutomaticTranscription}
@@ -385,6 +406,7 @@ const Locations: React.FC<LocationsProps> = ({
labelClassName="text-sm leading-6 whitespace-normal break-words"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
@@ -401,6 +423,7 @@ const Locations: React.FC<LocationsProps> = ({
labelClassName="text-sm leading-6 whitespace-normal break-words"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
@@ -417,6 +440,7 @@ const Locations: React.FC<LocationsProps> = ({
labelClassName="text-sm leading-6 whitespace-normal break-words"
checked={value}
onCheckedChange={onChange}
Badge={<UpgradeTeamsBadge checkForActiveStatus />}
/>
);
}}
@@ -159,6 +159,7 @@ export type FormValues = {
disableRecordingForOrganizer?: boolean;
disableRecordingForGuests?: boolean;
enableAutomaticTranscription?: boolean;
enableAutomaticRecordingForOrganizer?: boolean;
disableTranscriptionForGuests?: boolean;
disableTranscriptionForOrganizer?: boolean;
redirectUrlOnExit?: string;
@@ -398,6 +398,7 @@ export class BookingRepository {
disableRecordingForGuests: true,
disableRecordingForOrganizer: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: true,
disableTranscriptionForGuests: true,
disableTranscriptionForOrganizer: true,
redirectUrlOnExit: true,
@@ -7,6 +7,35 @@ export class CalVideoSettingsRepository {
});
}
static async createCalVideoSettings({
eventTypeId,
calVideoSettings,
}: {
eventTypeId: number;
calVideoSettings: {
disableRecordingForGuests?: boolean | null;
disableRecordingForOrganizer?: boolean | null;
enableAutomaticTranscription?: boolean | null;
enableAutomaticRecordingForOrganizer?: boolean | null;
disableTranscriptionForGuests?: boolean | null;
disableTranscriptionForOrganizer?: boolean | null;
redirectUrlOnExit?: string | null;
};
}) {
return await prisma.calVideoSettings.create({
data: {
disableRecordingForGuests: calVideoSettings.disableRecordingForGuests ?? false,
disableRecordingForOrganizer: calVideoSettings.disableRecordingForOrganizer ?? false,
enableAutomaticTranscription: calVideoSettings.enableAutomaticTranscription ?? false,
enableAutomaticRecordingForOrganizer: calVideoSettings.enableAutomaticRecordingForOrganizer ?? false,
disableTranscriptionForGuests: calVideoSettings.disableTranscriptionForGuests ?? false,
disableTranscriptionForOrganizer: calVideoSettings.disableTranscriptionForOrganizer ?? false,
redirectUrlOnExit: calVideoSettings.redirectUrlOnExit ?? null,
eventTypeId,
},
});
}
static async createOrUpdateCalVideoSettings({
eventTypeId,
calVideoSettings,
@@ -18,6 +47,7 @@ export class CalVideoSettingsRepository {
disableTranscriptionForGuests?: boolean | null;
disableTranscriptionForOrganizer?: boolean | null;
enableAutomaticTranscription?: boolean | null;
enableAutomaticRecordingForOrganizer?: boolean | null;
redirectUrlOnExit?: string | null;
};
}) {
@@ -27,6 +57,7 @@ export class CalVideoSettingsRepository {
disableRecordingForGuests: calVideoSettings.disableRecordingForGuests ?? false,
disableRecordingForOrganizer: calVideoSettings.disableRecordingForOrganizer ?? false,
enableAutomaticTranscription: calVideoSettings.enableAutomaticTranscription ?? false,
enableAutomaticRecordingForOrganizer: calVideoSettings.enableAutomaticRecordingForOrganizer ?? false,
disableTranscriptionForGuests: calVideoSettings.disableTranscriptionForGuests ?? false,
disableTranscriptionForOrganizer: calVideoSettings.disableTranscriptionForOrganizer ?? false,
redirectUrlOnExit: calVideoSettings.redirectUrlOnExit ?? null,
@@ -36,6 +67,7 @@ export class CalVideoSettingsRepository {
disableRecordingForGuests: calVideoSettings.disableRecordingForGuests ?? false,
disableRecordingForOrganizer: calVideoSettings.disableRecordingForOrganizer ?? false,
enableAutomaticTranscription: calVideoSettings.enableAutomaticTranscription ?? false,
enableAutomaticRecordingForOrganizer: calVideoSettings.enableAutomaticRecordingForOrganizer ?? false,
disableTranscriptionForGuests: calVideoSettings.disableTranscriptionForGuests ?? false,
disableTranscriptionForOrganizer: calVideoSettings.disableTranscriptionForOrganizer ?? false,
redirectUrlOnExit: calVideoSettings.redirectUrlOnExit ?? null,
@@ -709,6 +709,7 @@ export class EventTypeRepository {
disableRecordingForGuests: true,
disableRecordingForOrganizer: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: true,
disableTranscriptionForGuests: true,
disableTranscriptionForOrganizer: true,
redirectUrlOnExit: true,
@@ -177,6 +177,7 @@ export const useEventTypeForm = ({
disableRecordingForOrganizer: z.boolean().nullable(),
disableRecordingForGuests: z.boolean().nullable(),
enableAutomaticTranscription: z.boolean().nullable(),
enableAutomaticRecordingForOrganizer: z.boolean().nullable(),
disableTranscriptionForGuests: z.boolean().nullable(),
disableTranscriptionForOrganizer: z.boolean().nullable(),
})
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "CalVideoSettings" ADD COLUMN "enableAutomaticRecordingForOrganizer" BOOLEAN NOT NULL DEFAULT false;
+9 -9
View File
@@ -72,15 +72,15 @@ model CalVideoSettings {
eventTypeId Int @id
eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
disableRecordingForOrganizer Boolean @default(false)
disableRecordingForGuests Boolean @default(false)
enableAutomaticTranscription Boolean @default(false)
redirectUrlOnExit String?
disableTranscriptionForGuests Boolean @default(false)
disableTranscriptionForOrganizer Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
disableRecordingForOrganizer Boolean @default(false)
disableRecordingForGuests Boolean @default(false)
enableAutomaticTranscription Boolean @default(false)
enableAutomaticRecordingForOrganizer Boolean @default(false)
redirectUrlOnExit String?
disableTranscriptionForGuests Boolean @default(false)
disableTranscriptionForOrganizer Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model EventType {
@@ -1,6 +1,7 @@
import { Prisma } from "@prisma/client";
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
import { CalVideoSettingsRepository } from "@calcom/lib/server/repository/calVideoSettings";
import { EventTypeRepository } from "@calcom/lib/server/repository/eventType";
import { prisma } from "@calcom/prisma";
@@ -44,6 +45,17 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
webhooks: true,
hashedLink: true,
destinationCalendar: true,
calVideoSettings: {
select: {
disableRecordingForOrganizer: true,
disableRecordingForGuests: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: true,
redirectUrlOnExit: true,
disableTranscriptionForGuests: true,
disableTranscriptionForOrganizer: true,
},
},
},
});
@@ -95,6 +107,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
secondaryEmailId,
instantMeetingScheduleId: _instantMeetingScheduleId,
restrictionScheduleId: _restrictionScheduleId,
calVideoSettings,
...rest
} = eventType;
@@ -179,6 +192,13 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
});
}
if (calVideoSettings) {
await CalVideoSettingsRepository.createCalVideoSettings({
eventTypeId: newEventType.id,
calVideoSettings,
});
}
if (workflows.length > 0) {
const relationCreateData = workflows.map((workflow) => {
return { eventTypeId: newEventType.id, workflowId: workflow.workflowId };
@@ -27,12 +27,13 @@ const aiPhoneCallConfig = z
const calVideoSettingsSchema = z
.object({
disableRecordingForGuests: z.boolean().optional().nullable(),
disableRecordingForOrganizer: z.boolean().optional().nullable(),
enableAutomaticTranscription: z.boolean().optional().nullable(),
disableTranscriptionForGuests: z.boolean().optional().nullable(),
disableTranscriptionForOrganizer: z.boolean().optional().nullable(),
redirectUrlOnExit: z.string().url().optional().nullable(),
disableRecordingForGuests: z.boolean().nullish(),
disableRecordingForOrganizer: z.boolean().nullish(),
enableAutomaticTranscription: z.boolean().nullish(),
enableAutomaticRecordingForOrganizer: z.boolean().nullish(),
disableTranscriptionForGuests: z.boolean().nullish(),
disableTranscriptionForOrganizer: z.boolean().nullish(),
redirectUrlOnExit: z.string().url().nullish(),
})
.optional()
.nullable();
@@ -26,6 +26,7 @@ import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../types";
import { setDestinationCalendarHandler } from "../../viewer/calendars/setDestinationCalendar.handler";
import { hasTeamPlanHandler } from "../teams/hasTeamPlan.handler";
import type { TUpdateInputSchema } from "./update.schema";
import {
ensureUniqueBookingFields,
@@ -130,6 +131,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
disableRecordingForOrganizer: true,
disableRecordingForGuests: true,
enableAutomaticTranscription: true,
enableAutomaticRecordingForOrganizer: true,
disableTranscriptionForGuests: true,
disableTranscriptionForOrganizer: true,
redirectUrlOnExit: true,
@@ -598,10 +600,16 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
}
if (calVideoSettings) {
await CalVideoSettingsRepository.createOrUpdateCalVideoSettings({
eventTypeId: id,
calVideoSettings,
const { hasTeamPlan } = await hasTeamPlanHandler({
ctx: { user: ctx.user },
});
if (hasTeamPlan) {
await CalVideoSettingsRepository.createOrUpdateCalVideoSettings({
eventTypeId: id,
calVideoSettings,
});
}
}
const parsedEventTypeLocations = eventTypeLocations.safeParse(eventType.locations ?? []);
@@ -1,19 +1,16 @@
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
type HasTeamPlanOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
user: { id: number };
};
};
export const hasTeamPlanHandler = async ({ ctx }: HasTeamPlanOptions) => {
const userId = ctx.user.id;
export const hasTeamPlanHandler = async ({ ctx: { user } }: HasTeamPlanOptions) => {
const hasTeamPlan = await prisma.membership.findFirst({
where: {
accepted: true,
userId,
userId: user.id,
team: {
slug: {
not: null,
@@ -106,7 +106,7 @@ export function SettingsToggle({
<div>
<Label
className={classNames("text-emphasis text-sm font-semibold leading-none", labelClassName)}>
{title}
{title} {Badge ? Badge : null}
{LockedIcon}
</Label>
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}