fix: unify webhook ID resolution across handlers (#28701)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user