* allow event type specific webhooks for all event types * first version of team webhooks * add empty view * design fixes when no teams + invalidate query on delete/update * linke to new webhooks page with teamId in query * make one button with dropdown instead of a button for every team * add subtitle to dropdown * add avatar fallback * authorization when editing webhook * fix event type webhooks * fix authorization for delete handler * code clean up * fix disabled switch * add migration * fix subscriberUrlReservered function and fix authorization * fix type error * fix type error * fix switch not updating * make sure webhooks are triggered for the correct even types * code clean up * only show teams were user has write access * make webhooks read-only for members * fix comment * fix type error * fix webhook tests for team event types * implement feedback * code clean up from feedback * code clean up (feedback) * throw error if param missing in subscriberUrlReservered * handle null/undefined values in getWebhooks itself * better variable naming * better check if webhook is readonly * create assertPartOfTeamWithRequiredAccessLevel to remove duplicate code --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: alannnc <alannnc@gmail.com>
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import type { Prisma } from "@prisma/client";
|
|
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import type { TListInputSchema } from "./list.schema";
|
|
|
|
type ListOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TListInputSchema;
|
|
};
|
|
|
|
export const listHandler = async ({ ctx, input }: ListOptions) => {
|
|
const where: Prisma.WebhookWhereInput = {
|
|
/* Don't mixup zapier webhooks with normal ones */
|
|
AND: [{ appId: !input?.appId ? null : input.appId }],
|
|
};
|
|
|
|
const user = await prisma.user.findFirst({
|
|
where: {
|
|
id: ctx.user.id,
|
|
},
|
|
select: {
|
|
teams: true,
|
|
},
|
|
});
|
|
|
|
if (Array.isArray(where.AND)) {
|
|
if (input?.eventTypeId) {
|
|
where.AND?.push({ eventTypeId: input.eventTypeId });
|
|
} else {
|
|
where.AND?.push({
|
|
OR: [{ userId: ctx.user.id }, { teamId: { in: user?.teams.map((membership) => membership.teamId) } }],
|
|
});
|
|
}
|
|
}
|
|
|
|
return await prisma.webhook.findMany({
|
|
where,
|
|
});
|
|
};
|