* 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>
42 lines
780 B
TypeScript
42 lines
780 B
TypeScript
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TEditInputSchema } from "./edit.schema";
|
|
|
|
type EditOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TEditInputSchema;
|
|
};
|
|
|
|
export const editHandler = async ({ input, ctx }: EditOptions) => {
|
|
const { id, ...data } = input;
|
|
|
|
const webhook = await prisma.webhook.findFirst({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
if (!webhook) {
|
|
return null;
|
|
}
|
|
|
|
if (webhook.platform) {
|
|
const { user } = ctx;
|
|
if (user?.role !== "ADMIN") {
|
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
}
|
|
}
|
|
|
|
return await prisma.webhook.update({
|
|
where: {
|
|
id,
|
|
},
|
|
data,
|
|
});
|
|
};
|