fix: custom templates on team plan (#18792)
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
This commit is contained in:
co-authored by
CarinaWolli
parent
65b70d682d
commit
f523ce7795
@@ -91,7 +91,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
{ enabled: !!teamId }
|
||||
);
|
||||
|
||||
const { hasActiveTeamPlan } = useHasActiveTeamPlan(teamId);
|
||||
const { hasActiveTeamPlan } = useHasActiveTeamPlan();
|
||||
|
||||
const { data: _verifiedEmails } = trpc.viewer.workflows.getVerifiedEmails.useQuery({ teamId });
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export function useHasEnterprisePlan() {
|
||||
export function useHasActiveTeamPlan(teamId?: number) {
|
||||
if (IS_SELF_HOSTED) return { isPending: false, hasActiveTeamPlan: true };
|
||||
|
||||
const { data, isPending } = trpc.viewer.teams.hasActiveTeamPlan.useQuery({ teamId });
|
||||
const { data, isPending } = trpc.viewer.teams.hasActiveTeamPlan.useQuery();
|
||||
|
||||
return { isPending, hasActiveTeamPlan: !!data };
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import { ZGetSchema } from "./get.schema";
|
||||
import { ZGetMemberAvailabilityInputSchema } from "./getMemberAvailability.schema";
|
||||
import { ZGetMembershipbyUserInputSchema } from "./getMembershipbyUser.schema";
|
||||
import { ZGetUserConnectedAppsInputSchema } from "./getUserConnectedApps.schema";
|
||||
import { ZHasActiveTeamPlanSchema } from "./hasActiveTeamPlan.schema";
|
||||
import { ZHasEditPermissionForUserSchema } from "./hasEditPermissionForUser.schema";
|
||||
import { ZInviteMemberInputSchema } from "./inviteMember/inviteMember.schema";
|
||||
import { ZInviteMemberByTokenSchemaInputSchema } from "./inviteMemberByToken.schema";
|
||||
@@ -223,7 +222,7 @@ export const viewerTeamsRouter = router({
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
hasActiveTeamPlan: authedProcedure.input(ZHasActiveTeamPlanSchema).query(async (opts) => {
|
||||
hasActiveTeamPlan: authedProcedure.query(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("hasActiveTeamPlan"),
|
||||
() => import("./hasActiveTeamPlan.handler")
|
||||
|
||||
@@ -3,39 +3,37 @@ import { IS_SELF_HOSTED } from "@calcom/lib/constants";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { THasActiveTeamPlanSchema } from "./hasActiveTeamPlan.schema";
|
||||
|
||||
type HasActiveTeamPlanOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
input: THasActiveTeamPlanSchema;
|
||||
};
|
||||
|
||||
export const hasActiveTeamPlanHandler = async ({ input, ctx }: HasActiveTeamPlanOptions) => {
|
||||
export const hasActiveTeamPlanHandler = async ({ ctx }: HasActiveTeamPlanOptions) => {
|
||||
if (IS_SELF_HOSTED) return true;
|
||||
|
||||
if (!input.teamId) return false;
|
||||
|
||||
const userId = ctx.user.id;
|
||||
|
||||
// Check if the user is a member of the requested team
|
||||
const team = await prisma.team.findFirst({
|
||||
const teams = await prisma.team.findMany({
|
||||
where: {
|
||||
id: input.teamId,
|
||||
members: {
|
||||
some: {
|
||||
userId: userId,
|
||||
userId: ctx.user.id,
|
||||
accepted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!team) return false;
|
||||
|
||||
// Get the current team's subscription
|
||||
const teamBillingService = new InternalTeamBilling(team);
|
||||
return await teamBillingService.checkIfTeamHasActivePlan();
|
||||
if (!teams.length) return false;
|
||||
|
||||
// check if user has at least on membership with an active plan
|
||||
for (const team of teams) {
|
||||
const teamBillingService = new InternalTeamBilling(team);
|
||||
const isPlanActive = await teamBillingService.checkIfTeamHasActivePlan();
|
||||
if (isPlanActive) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export default hasActiveTeamPlanHandler;
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZHasActiveTeamPlanSchema = z.object({
|
||||
teamId: z.number().optional(),
|
||||
});
|
||||
|
||||
export type THasActiveTeamPlanSchema = z.infer<typeof ZHasActiveTeamPlanSchema>;
|
||||
export {};
|
||||
|
||||
@@ -84,7 +84,6 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
if (!isCurrentUsernamePremium) {
|
||||
isTeamsPlan = await hasActiveTeamPlanHandler({
|
||||
ctx,
|
||||
input: { teamId: userWorkflow?.teamId ?? undefined },
|
||||
});
|
||||
}
|
||||
const hasPaidPlan = IS_SELF_HOSTED || isCurrentUsernamePremium || isTeamsPlan;
|
||||
|
||||
Reference in New Issue
Block a user