Scheduling infrastructure for absolutely everyone.
Fix with upstream (#263)
Alex van Andelb6c3dce6921d
diff --git a/lib/utils/isAdmin.ts b/lib/utils/isAdmin.tsindex c07086fbd67..9db0cb5026a 100644--- a/lib/utils/isAdmin.ts+++ b/lib/utils/isAdmin.ts@@ -1,6 +1,7 @@-import { UserPermissionRole } from "@prisma/client";import type { NextApiRequest } from "next/types";+import { UserPermissionRole } from "@calcom/prisma/enums";+export const isAdminGuard = async (req: NextApiRequest) => {const { userId, prisma } = req;const user = await prisma.user.findUnique({ where: { id: userId } });diff --git a/lib/validations/membership.ts b/lib/validations/membership.tsindex 90b4e966fbe..24740eaa52f 100644--- a/lib/validations/membership.ts+++ b/lib/validations/membership.ts@@ -1,6 +1,6 @@-import { MembershipRole } from "@prisma/client";import { z } from "zod";+import { MembershipRole } from "@calcom/prisma/enums";import { _MembershipModel as Membership, _TeamModel } from "@calcom/prisma/zod";import { stringOrNumber } from "@calcom/prisma/zod-utils";diff --git a/pages/api/event-types/[id]/_patch.ts b/pages/api/event-types/[id]/_patch.tsindex 83bdf156ad7..2468d1621b7 100644--- a/pages/api/event-types/[id]/_patch.ts+++ b/pages/api/event-types/[id]/_patch.ts@@ -1,10 +1,10 @@import type { Prisma } from "@prisma/client";-import { SchedulingType } from "@prisma/client";import type { NextApiRequest } from "next";import type { z } from "zod";import { HttpError } from "@calcom/lib/http-error";import { defaultResponder } from "@calcom/lib/server";+import { SchedulingType } from "@calcom/prisma/enums";import type { schemaEventTypeBaseBodyParams } from "~/lib/validations/event-type";import { schemaEventTypeEditBodyParams, schemaEventTypeReadPublic } from "~/lib/validations/event-type";diff --git a/pages/api/teams/[teamId]/_auth-middleware.ts b/pages/api/teams/[teamId]/_auth-middleware.tsindex e6fd918043c..bde11bb75c3 100644--- a/pages/api/teams/[teamId]/_auth-middleware.ts+++ b/pages/api/teams/[teamId]/_auth-middleware.ts@@ -1,8 +1,8 @@import type { Prisma } from "@prisma/client";-import { MembershipRole } from "@prisma/client";import type { NextApiRequest } from "next";import { HttpError } from "@calcom/lib/http-error";+import { MembershipRole } from "@calcom/prisma/enums";import { schemaQueryTeamId } from "~/lib/validations/shared/queryTeamId";diff --git a/pages/api/teams/[teamId]/publish.ts b/pages/api/teams/[teamId]/publish.tsindex edb36be7966..25f1c747858 100644--- a/pages/api/teams/[teamId]/publish.ts+++ b/pages/api/teams/[teamId]/publish.ts@@ -1,10 +1,10 @@-import { MembershipRole, UserPermissionRole } from "@prisma/client";import type { NextApiRequest, NextApiResponse } from "next";import { HttpError } from "@calcom/lib/http-error";import { defaultHandler, defaultResponder } from "@calcom/lib/server";+import { MembershipRole, UserPermissionRole } from "@calcom/prisma/enums";import { createContext } from "@calcom/trpc/server/createContext";-import { viewerRouter } from "@calcom/trpc/server/routers/viewer";+import { publishHandler } from "@calcom/trpc/server/routers/viewer/teams/publish.handler";import { TRPCError } from "@trpc/server";import { getHTTPStatusCodeFromError } from "@trpc/server/http";@@ -33,10 +33,13 @@ const patchHandler = async (req: NextApiRequest, res: NextApiResponse) => {/** @see https://trpc.io/docs/server-side-calls */const ctx = await createContext({ req, res }, sessionGetter);- const caller = viewerRouter.createCaller(ctx);+ const user = ctx.user;+ if (!user) {+ throw new Error("Internal Error.");+ }try {const { teamId } = schemaQueryTeamId.parse(req.query);- return await caller.teams.publish({ teamId });+ return await publishHandler({ input: { teamId }, ctx: { ...ctx, user } });} catch (cause) {if (cause instanceof TRPCError) {const statusCode = getHTTPStatusCodeFromError(cause);diff --git a/pages/api/teams/_post.ts b/pages/api/teams/_post.tsindex af032d00d47..56e0820535e 100644--- a/pages/api/teams/_post.ts+++ b/pages/api/teams/_post.ts@@ -1,9 +1,9 @@-import { MembershipRole } from "@prisma/client";import type { NextApiRequest } from "next";import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";import { HttpError } from "@calcom/lib/http-error";import { defaultResponder } from "@calcom/lib/server";+import { MembershipRole } from "@calcom/prisma/enums";import { schemaMembershipPublic } from "~/lib/validations/membership";import { schemaTeamBodyParams, schemaTeamReadPublic } from "~/lib/validations/team";