Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🚸 Require picking webhook events instead of preselecting all (#3347)

Luke Vellab6b5a009e0b7
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index bae84e6bb..36f6c29b6 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -996,6 +996,7 @@
"webhookDeleted": "Webhook deleted",
"webhookDocs": "Webhook docs",
"webhookEventComboboxEmpty": "No events found",
+ "webhookEventComboboxPlaceholder": "Select events",
"webhookEventCount": "{count, plural, one {# event} other {# events}}",
"webhookHealthDisabledAfterFailures": "Turned off after failures",
"webhookHealthFailedInARow": "{count, plural, one {# event} other {# events}} failed in a row",
diff --git a/apps/web/src/features/webhook/components/create-webhook-button.tsx b/apps/web/src/features/webhook/components/create-webhook-button.tsx
index 7e06f6c7e..dcb97a5ca 100644
--- a/apps/web/src/features/webhook/components/create-webhook-button.tsx
+++ b/apps/web/src/features/webhook/components/create-webhook-button.tsx
@@ -31,7 +31,7 @@ import { useCopyToClipboard } from "react-use";
import { Trans, useTranslation } from "@/i18n/client";
import { useSafeAction } from "@/lib/safe-action/client";
import { createWebhookAction } from "../actions";
-import { createWebhookInputSchema, WEBHOOK_EVENT_TYPES } from "../schema";
+import { createWebhookInputSchema } from "../schema";
import { WebhookEventCombobox } from "./webhook-event-combobox";
export function CreateWebhookButton() {
@@ -46,7 +46,7 @@ export function CreateWebhookButton() {
resolver: zodResolver(createWebhookInputSchema),
defaultValues: {
url: "",
- events: [...WEBHOOK_EVENT_TYPES],
+ events: [],
},
});
diff --git a/apps/web/src/features/webhook/components/webhook-event-combobox.tsx b/apps/web/src/features/webhook/components/webhook-event-combobox.tsx
index 33b2bd06b..06c7037c3 100644
--- a/apps/web/src/features/webhook/components/webhook-event-combobox.tsx
+++ b/apps/web/src/features/webhook/components/webhook-event-combobox.tsx
@@ -52,10 +52,17 @@ export function WebhookEventCombobox({
<ComboboxInput
id={id}
onBlur={onBlur}
- placeholder={t("webhookEventCount", {
- defaultValue: "{count, plural, one {# event} other {# events}}",
- count: value.length,
- })}
+ placeholder={
+ value.length > 0
+ ? t("webhookEventCount", {
+ defaultValue:
+ "{count, plural, one {# event} other {# events}}",
+ count: value.length,
+ })
+ : t("webhookEventComboboxPlaceholder", {
+ defaultValue: "Select events",
+ })
+ }
{...ariaProps}
/>
</div>
diff --git a/apps/web/src/features/webhook/schema.ts b/apps/web/src/features/webhook/schema.ts
index 1d54c6893..3445d9d73 100644
--- a/apps/web/src/features/webhook/schema.ts
+++ b/apps/web/src/features/webhook/schema.ts
@@ -286,9 +286,13 @@ export const webhookUrlSchema = z
// to a run, and keeps the list readable.
export const MAX_WEBHOOKS_PER_SPACE = 5;
+const webhookEventsSchema = z
+ .array(webhookEventTypeSchema)
+ .min(1, "Select at least one event");
+
export const createWebhookInputSchema = z.object({
url: webhookUrlSchema,
- events: z.array(webhookEventTypeSchema).min(1),
+ events: webhookEventsSchema,
});
export type CreateWebhookInput = z.infer<typeof createWebhookInputSchema>;
@@ -296,7 +300,7 @@ export type CreateWebhookInput = z.infer<typeof createWebhookInputSchema>;
export const updateWebhookInputSchema = z.object({
webhookId: z.string(),
url: webhookUrlSchema.optional(),
- events: z.array(webhookEventTypeSchema).min(1).optional(),
+ events: webhookEventsSchema.optional(),
enabled: z.boolean().optional(),
});
diff --git a/apps/web/tests/webhooks-settings.spec.ts b/apps/web/tests/webhooks-settings.spec.ts
index 9f6c4edbb..ce8f8f3bf 100644
--- a/apps/web/tests/webhooks-settings.spec.ts
+++ b/apps/web/tests/webhooks-settings.spec.ts
@@ -10,7 +10,6 @@ import {
MAX_CONSECUTIVE_FAILURES,
WEBHOOK_VERSION,
} from "@/features/webhook/constants";
-import { WEBHOOK_EVENT_TYPES } from "@/features/webhook/schema";
import {
createUserInDb,
loginWithEmail,
@@ -163,10 +162,18 @@ test.describe("Webhooks settings", () => {
await page.getByRole("button", { name: "Add webhook" }).click();
const url = "https://example.com/hooks/rallly";
await page.getByLabel("URL").fill(url);
- await page
+ const submit = page
.getByRole("dialog")
- .getByRole("button", { name: "Add webhook" })
- .click();
+ .getByRole("button", { name: "Add webhook" });
+
+ // No events are preselected, and at least one is required.
+ await submit.click();
+ await expect(page.getByText("Select at least one event")).toBeVisible();
+
+ await page.getByLabel("Events").click();
+ await page.getByRole("option", { name: "poll.closed" }).click();
+ await page.keyboard.press("Escape");
+ await submit.click();
// The secret is shown once, and it is the real one: what the dialog
// displays must decrypt back out of the row the dispatcher signs with.
@@ -183,8 +190,7 @@ test.describe("Webhooks settings", () => {
// Pinned at creation, so a later version bump cannot move an endpoint
// that was built against this one.
expect(webhook.version).toBe(WEBHOOK_VERSION);
- // The form starts with every event selected.
- expect([...webhook.events].sort()).toEqual([...WEBHOOK_EVENT_TYPES].sort());
+ expect(webhook.events).toEqual(["poll.closed"]);
expect(decryptSecret(webhook.secret)).toBe(revealed);
// Never replays history: a new endpoint starts at now.
expect(webhook.cursor.getTime()).toBeGreaterThan(Date.now() - 60_000);
@@ -194,9 +200,7 @@ test.describe("Webhooks settings", () => {
const row = endpointRow(page, url);
await expect(row).toBeVisible();
// The row summarises the subscription rather than listing it.
- await expect(
- row.getByText(`${WEBHOOK_EVENT_TYPES.length} events`),
- ).toBeVisible();
+ await expect(row.getByText("1 event")).toBeVisible();
// Closing the reveal is the only chance to copy it — reloading must not
// surface the secret again.
await page.reload();