feat: Add booking and user creation source (#18768)
* migration and init to accept creationSource for new bookings * V1 create booking * V1 user creation * webapp booking + V1 user * user creation in V1, V2 and webapp * booking source V2 and fix for v1 user * fit type * --fix type * add test -- WIP * fix type * fix type * ^ * Need more sleep zzz * -_- * bump libraries platform * adds for v2 recurring booking * fix lint * instant meetings * fix: api v2 creation source * fixup! fix: api v2 creation source * bump libraries * add user * fix test * fixup! fix test * add more source * more source... * fix type & test --1 * fix type & test --2 * typefix * fixup test --------- Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
1 parent
3f622fe277
commit
41f63582b2
46 files changed
+261
-18
No files matched your search
@@ -36,6 +36,7 @@ import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { IdentityProvider, MembershipRole } from "@calcom/prisma/enums";
|
||||
import { teamMetadataSchema, userMetadata } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -979,6 +980,7 @@ export const getOptions = ({
|
||||
create: { role: MembershipRole.MEMBER, accepted: true, team: { connect: { id: orgId } } },
|
||||
},
|
||||
}),
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import logger from "@calcom/lib/logger";
|
||||
import { usernameHandler, type RequestWithUsernameStatus } from "@calcom/lib/server/username";
|
||||
import { validateAndGetCorrectedUsernameAndEmail } from "@calcom/lib/validateUsername";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { IdentityProvider } from "@calcom/prisma/enums";
|
||||
import { signupSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -199,6 +200,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
|
||||
stripeCustomerId: customer.id,
|
||||
checkoutSessionId,
|
||||
},
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
});
|
||||
if (process.env.AVATARAPI_USERNAME && process.env.AVATARAPI_PASSWORD) {
|
||||
|
||||
@@ -68,6 +68,7 @@ import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import {
|
||||
eventTypeAppMetadataOptionalSchema,
|
||||
eventTypeMetaDataSchemaWithTypedApps,
|
||||
@@ -277,6 +278,7 @@ const buildDryRunBooking = ({
|
||||
ratingFeedback: null,
|
||||
noShowHost: null,
|
||||
cancelledBy: null,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
} as CreatedBooking;
|
||||
|
||||
/**
|
||||
@@ -1195,6 +1197,7 @@ async function handler(
|
||||
},
|
||||
evt,
|
||||
originalRescheduledBooking,
|
||||
creationSource: req.body.creationSource,
|
||||
});
|
||||
|
||||
if (booking?.userId) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import dayjs from "@calcom/dayjs";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { CreationSource } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { TgetBookingDataSchema } from "../getBookingDataSchema";
|
||||
@@ -51,6 +52,7 @@ type CreateBookingParams = {
|
||||
};
|
||||
evt: CalendarEvent;
|
||||
originalRescheduledBooking: OriginalRescheduledBooking;
|
||||
creationSource?: CreationSource;
|
||||
};
|
||||
|
||||
function updateEventDetails(
|
||||
@@ -85,6 +87,7 @@ export async function createBooking({
|
||||
routingFormResponseId,
|
||||
reroutingFormResponses,
|
||||
rescheduledBy,
|
||||
creationSource,
|
||||
}: CreateBookingParams & { rescheduledBy: string | undefined }) {
|
||||
updateEventDetails(evt, originalRescheduledBooking, input.changedOrganizer);
|
||||
const associatedBookingForFormResponse = routingFormResponseId
|
||||
@@ -101,6 +104,7 @@ export async function createBooking({
|
||||
input,
|
||||
evt,
|
||||
originalRescheduledBooking,
|
||||
creationSource,
|
||||
});
|
||||
|
||||
return await saveBooking(
|
||||
@@ -211,6 +215,7 @@ function buildNewBookingData(params: CreateBookingParams) {
|
||||
routingFormResponseId,
|
||||
reroutingFormResponses,
|
||||
rescheduledBy,
|
||||
creationSource,
|
||||
} = params;
|
||||
|
||||
const attendeesData = getAttendeesData(evt);
|
||||
@@ -258,6 +263,7 @@ function buildNewBookingData(params: CreateBookingParams) {
|
||||
routedFromRoutingFormReponse: routingFormResponseId
|
||||
? { connect: { id: routingFormResponseId } }
|
||||
: undefined,
|
||||
creationSource,
|
||||
};
|
||||
|
||||
if (reqBody.recurringEventId) {
|
||||
|
||||
@@ -56,6 +56,7 @@ import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { WEBSITE_URL, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { resetTestEmails } from "@calcom/lib/testEmails";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
@@ -1549,6 +1550,86 @@ describe("handleNewBooking", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("Creation source tests", () => {
|
||||
test(
|
||||
`should create a booking with creation source as WEBAPP`,
|
||||
async ({ emails }) => {
|
||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getZoomAppCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
});
|
||||
|
||||
const { req } = createMockNextJsRequest({
|
||||
method: "POST",
|
||||
body: getMockRequestDataForBooking({
|
||||
data: {
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
},
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const scenarioData = getScenarioData({
|
||||
webhooks: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
eventTriggers: ["BOOKING_CREATED"],
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
active: true,
|
||||
eventTypeId: 1,
|
||||
appId: null,
|
||||
},
|
||||
],
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
length: 30,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
locations: [
|
||||
{
|
||||
type: BookingLocations.ZoomVideo,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["zoomvideo"]],
|
||||
});
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "zoomvideo",
|
||||
});
|
||||
await createBookingScenario(scenarioData);
|
||||
const createdBooking = await handleNewBooking(req);
|
||||
expect(createdBooking).toEqual(
|
||||
expect.objectContaining({
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
})
|
||||
);
|
||||
},
|
||||
timeout
|
||||
);
|
||||
});
|
||||
|
||||
describe(
|
||||
"Availability Check during booking",
|
||||
() => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { TFunction } from "next-i18next";
|
||||
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { getTeamOrThrow } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";
|
||||
import { sendSignupToOrganizationEmail } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";
|
||||
@@ -46,6 +47,7 @@ const createUserAndInviteToOrg = async ({
|
||||
],
|
||||
},
|
||||
},
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createOrUpdateMemberships } from "@calcom/features/auth/signup/utils/cr
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { IdentityProvider } from "@calcom/prisma/enums";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
|
||||
import dSyncUserSelect from "./dSyncUserSelect";
|
||||
|
||||
@@ -37,6 +38,7 @@ const createUsersAndConnectToOrg = async (
|
||||
organizationId,
|
||||
identityProvider,
|
||||
identityProviderId,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ import { classNames } from "@calcom/lib";
|
||||
import { IS_TEAM_BILLING_ENABLED_CLIENT } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, CheckboxField, Form, Icon, showToast, TextField } from "@calcom/ui";
|
||||
@@ -151,7 +152,12 @@ const AddNewTeamsFormChild = ({
|
||||
const handleFormSubmit = () => {
|
||||
const fields = getValues("teams");
|
||||
const moveTeams = getValues("moveTeams");
|
||||
createTeamsMutation.mutate({ orgId: org.id, moveTeams, teamNames: fields.map((field) => field.name) });
|
||||
createTeamsMutation.mutate({
|
||||
orgId: org.id,
|
||||
moveTeams,
|
||||
teamNames: fields.map((field) => field.name),
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
});
|
||||
};
|
||||
|
||||
const moveTeams = watch("moveTeams");
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { Ensure } from "@calcom/types/utils";
|
||||
import { Alert, Button, Form, Label, RadioGroup as RadioArea, TextField, ToggleGroup } from "@calcom/ui";
|
||||
@@ -107,7 +108,7 @@ const CreateANewOrganizationFormChild = ({
|
||||
handleSubmit={(v) => {
|
||||
if (!createOrganizationMutation.isPending) {
|
||||
setServerErrorMessage(null);
|
||||
createOrganizationMutation.mutate(v);
|
||||
createOrganizationMutation.mutate({ ...v, creationSource: CreationSource.WEBAPP });
|
||||
}
|
||||
}}>
|
||||
<div>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useState, useEffect } from "react";
|
||||
import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
@@ -216,6 +217,7 @@ const MembersView = () => {
|
||||
language: i18n.language,
|
||||
role: values.role,
|
||||
usernameOrEmail: values.emailOrUsername,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
{
|
||||
onSuccess: async (data) => {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { Ensure } from "@calcom/types/utils";
|
||||
import { Alert, Form, TextField, Button } from "@calcom/ui";
|
||||
@@ -91,6 +92,7 @@ const CreateANewPlatformFormChild = ({ session }: { session: Ensure<SessionConte
|
||||
createOrganizationMutation.mutate({
|
||||
...v,
|
||||
slug: `${v.name.toLocaleLowerCase()}-platform-${uuid().substring(0, 20)}`,
|
||||
creationSource: CreationSource.API_V2,
|
||||
});
|
||||
}
|
||||
}}>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { IS_TEAM_BILLING_ENABLED_CLIENT, MAX_NB_INVITES } from "@calcom/lib/cons
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import type { RouterOutputs } from "@calcom/trpc";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import { isEmail } from "@calcom/trpc/server/routers/viewer/teams/util";
|
||||
@@ -512,6 +513,7 @@ export const MemberInvitationModalWithoutMembers = ({
|
||||
language: i18n.language,
|
||||
role: values.role,
|
||||
usernameOrEmail: values.emailOrUsername,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
},
|
||||
{
|
||||
onSuccess: async (data) => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Alert, Button, ButtonGroup, EmptyScreen, Icon, Label, showToast } from "@calcom/ui";
|
||||
|
||||
@@ -95,7 +96,7 @@ export function TeamsListing() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!router) return;
|
||||
if (token) inviteMemberByToken({ token });
|
||||
if (token) inviteMemberByToken({ token, creationSource: CreationSource.WEBAPP });
|
||||
else setInviteTokenChecked(true);
|
||||
}, [router, inviteMemberByToken, setInviteTokenChecked, token]);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { RedirectType } from "@calcom/prisma/enums";
|
||||
import { _UserModel as User } from "@calcom/prisma/zod";
|
||||
import type { inferRouterOutputs } from "@calcom/trpc";
|
||||
@@ -63,7 +64,7 @@ export const userAdminRouter = router({
|
||||
}),
|
||||
add: authedAdminProcedure.input(userBodySchema).mutation(async ({ ctx, input }) => {
|
||||
const { prisma } = ctx;
|
||||
const user = await prisma.user.create({ data: input });
|
||||
const user = await prisma.user.create({ data: { ...input, creationSource: CreationSource.WEBAPP } });
|
||||
return { user, message: `User with id: ${user.id} added successfully` };
|
||||
}),
|
||||
update: authedAdminProcedureWithRequestedUser
|
||||
|
||||
@@ -261,6 +261,7 @@ async function handler(req: NextApiRequest) {
|
||||
data: attendeesList,
|
||||
},
|
||||
},
|
||||
creationSource: req.body.creationSource,
|
||||
};
|
||||
|
||||
const createBookingObj = {
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Dispatch } from "react";
|
||||
|
||||
import MemberInvitationModal from "@calcom/features/ee/teams/components/MemberInvitationModal";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import { showToast } from "@calcom/ui";
|
||||
import usePlatformMe from "@calcom/web/components/settings/platform/hooks/usePlatformMe";
|
||||
@@ -70,6 +71,7 @@ export function InviteMemberModal(props: Props) {
|
||||
role: values.role,
|
||||
usernameOrEmail: values.emailOrUsername,
|
||||
isPlatform: platformUser?.organization.isPlatform,
|
||||
creationSource: CreationSource.WEBAPP,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user