* db migration * adjusted ui to include `platform` in dropdown for admin webhooks * adjusted webhook/create.handler for platform * adjusted `edit.handler` so that only ADMIN can update `platform` webhooks * update `getWebhooks` for platform wide webhooks * list platform webhooks if admin * createFunction refactor * update subscriberUrlReserved for platform webhooks * fix delete webhook handler * fix: added readOnly to WebhookListItem * fix: admin cannot delete its own webhooks * fix: ts error --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import type { Prisma } from "@prisma/client";
|
|
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import type { TDeleteInputSchema } from "./delete.schema";
|
|
|
|
type DeleteOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TDeleteInputSchema;
|
|
};
|
|
|
|
export const deleteHandler = async ({ ctx, input }: DeleteOptions) => {
|
|
const { id } = input;
|
|
|
|
const where: Prisma.WebhookWhereInput = { AND: [{ id: id }] };
|
|
|
|
if (Array.isArray(where.AND)) {
|
|
if (input.eventTypeId) {
|
|
where.AND.push({ eventTypeId: input.eventTypeId });
|
|
} else if (input.teamId) {
|
|
where.AND.push({ teamId: input.teamId });
|
|
} else if (ctx.user.role == "ADMIN") {
|
|
where.AND.push({ OR: [{ platform: true }, { userId: ctx.user.id }] });
|
|
} else {
|
|
where.AND.push({ userId: ctx.user.id });
|
|
}
|
|
}
|
|
|
|
const webhookToDelete = await prisma.webhook.findFirst({
|
|
where,
|
|
});
|
|
|
|
if (webhookToDelete) {
|
|
await prisma.webhook.delete({
|
|
where: {
|
|
id: webhookToDelete.id,
|
|
},
|
|
});
|
|
}
|
|
|
|
return {
|
|
id,
|
|
};
|
|
};
|