fix: unify webhook ID resolution across handlers (#28701)

This commit is contained in:
Pedro Castro
2026-04-01 16:29:55 -03:00
committed by GitHub
parent 2e5643e192
commit 9b3bbb9f72
6 changed files with 10 additions and 9 deletions
@@ -33,9 +33,10 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
});
}
const { webhookId: _webhookId, ...inputWithoutWebhookId } = input;
const webhookData: Prisma.WebhookCreateInput = {
id: v4(),
...input,
...inputWithoutWebhookId,
};
if (input.platform && user.role !== "ADMIN") {
throw new TRPCError({ code: "UNAUTHORIZED" });
@@ -21,7 +21,7 @@ type EditOptions = {
};
export const editHandler = async ({ input, ctx }: EditOptions) => {
const { id, ...data } = input;
const { id, webhookId: _webhookId, ...data } = input;
const webhook = await prisma.webhook.findUnique({
where: {
@@ -11,5 +11,5 @@ type GetOptions = {
export const getHandler = async ({ ctx: _ctx, input }: GetOptions) => {
const { repository: webhookRepository } = getWebhookFeature();
return await webhookRepository.findByWebhookId(input.webhookId);
return await webhookRepository.findByWebhookId(input.id || input.webhookId);
};
@@ -2,8 +2,6 @@ import { z } from "zod";
import { webhookIdAndEventTypeIdSchema } from "./types";
export const ZGetInputSchema = webhookIdAndEventTypeIdSchema.extend({
webhookId: z.string().optional(),
});
export const ZGetInputSchema = webhookIdAndEventTypeIdSchema;
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
@@ -4,6 +4,7 @@ import { z } from "zod";
export const webhookIdAndEventTypeIdSchema = z.object({
// Webhook ID
id: z.string().optional(),
webhookId: z.string().optional(),
eventTypeId: z.number().optional(),
teamId: z.number().optional(),
});
@@ -22,13 +22,14 @@ export const createWebhookPbacProcedure = (
// Endpoints that just read the logged in user's data - like 'list' don't necessarily have any input
if (!input) return next();
const { id, teamId, eventTypeId } = input;
const { id, webhookId, teamId, eventTypeId } = input;
const lookupId = id || webhookId;
const permissionCheckService = new PermissionCheckService();
if (id) {
if (lookupId) {
// Check if user is authorized to edit webhook
const webhook = await prisma.webhook.findUnique({
where: { id },
where: { id: lookupId },
select: {
id: true,
userId: true,