Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(content): show a member the webhook settings read-only, so Test and Save aren't pressed only to be refused (#1673)

Cihan5d336b8a19a5
diff --git a/docs/api-reference/webhooks.mdx b/docs/api-reference/webhooks.mdx
index 2c018a592..58faf38ce 100644
--- a/docs/api-reference/webhooks.mdx
+++ b/docs/api-reference/webhooks.mdx
@@ -296,7 +296,7 @@ The test uses the URL and secret currently in the form, so you can check an endp
- Respond with a 2xx status quickly and do slow work after responding. Once the status has arrived, it counts, even if the rest of the answer is cut off or doesn't arrive in time.
- Redirects aren't followed: a 3xx is the answer, and nothing reaches the address it points to. Use that address; the **Test** button reports a 3xx as a failure and names where it redirects to.
- When the **Test** button can't reach the webhook, it adds the network error, such as `ENOTFOUND` (the host name doesn't resolve), `ECONNREFUSED` (nothing listens on that port) or a TLS certificate error.
-- Only admins and managers can test a brand's webhook, up to 10 tests a minute each.
+- Only admins and managers can change or test a brand's webhook, up to 10 tests a minute each. Other members see its settings read-only.
- The address must be `http://` or `https://`, with no user name or password in it. On Ansvisor Cloud it must also be a public address. A self-hosted install may also use addresses on its own network.
- `content_draft.sent`:
- A 2xx answer marks the send **sent**. Anything else, or no answer, marks it **failed**, and the Library shows why. The first 2,000 characters of the answer are kept.
diff --git a/web/messages/en.json b/web/messages/en.json
index 29531c8d2..4b3194c45 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -6148,6 +6148,7 @@
"testFailed": "Webhook test failed: {error}",
"testRedirect": "The address redirects (HTTP {status}) to {location}. Nothing is sent on to it: use that address instead.",
"testForbidden": "Only admins and managers can test the webhook.",
+ "readOnly": "Only admins and managers can change or test this webhook.",
"save": "Save Webhook",
"saving": "Saving...",
"saved": "Webhook saved!",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.test.tsx
index 692cf003d..711d431f5 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.test.tsx
@@ -4,6 +4,7 @@ import { NextIntlClientProvider } from 'next-intl';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import messages from '../../../../../../messages/en.json';
import type { WebhookTestResult } from '@/lib/actions/content';
+import { RoleProvider, type TeamRole } from '@/components/providers/role-provider';
const getWebhookConfig = vi.hoisted(() => vi.fn());
const testWebhook = vi.hoisted(() => vi.fn());
@@ -28,11 +29,13 @@ const { WebhookSettingsDialog } = await import('./_webhook-settings');
let container: HTMLDivElement;
let root: Root;
-async function render() {
+async function render(role: TeamRole = 'manager') {
await act(async () => {
root.render(
<NextIntlClientProvider locale="en" messages={messages}>
- <WebhookSettingsDialog open onOpenChange={vi.fn()} brandId="brand-1" />
+ <RoleProvider role={role}>
+ <WebhookSettingsDialog open onOpenChange={vi.fn()} brandId="brand-1" />
+ </RoleProvider>
</NextIntlClientProvider>,
);
});
@@ -74,6 +77,28 @@ describe('WebhookSettingsDialog – Test Webhook', () => {
expect(testWebhook).toHaveBeenCalledWith('brand-1', 'https://hooks.example/abc', 'shh');
});
+ it('shows a member the webhook, and why it can’t be changed or tested, before anything is pressed (#1605)', async () => {
+ await render('analyst');
+ expect(dialog().textContent).toContain(
+ 'Only admins and managers can change or test this webhook.',
+ );
+ expect(button('Test Webhook').disabled).toBe(true);
+ expect(button('Save Webhook').disabled).toBe(true);
+ expect((dialog().querySelector('#webhook-url') as HTMLInputElement).value).toBe(
+ 'https://hooks.example/abc',
+ );
+ expect((dialog().querySelector('#webhook-url') as HTMLInputElement).disabled).toBe(true);
+ const toggle = dialog().querySelector('[role="switch"]')!;
+ expect(toggle.hasAttribute('disabled')).toBe(true);
+ // Dimmed, with the not-allowed cursor, as the disabled checkboxes beside it.
+ expect(toggle.className).toContain('disabled:cursor-not-allowed');
+ expect(toggle.className).toContain('disabled:opacity-50');
+
+ await render('admin');
+ expect(dialog().textContent).not.toContain('Only admins and managers can change');
+ expect(button('Test Webhook').disabled).toBe(false);
+ });
+
it('says only admins and managers can test', async () => {
expect(await runTest({ success: false, status: 0, failure: 'forbidden' })).toContain(
'Only admins and managers can test the webhook.',
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.tsx
index 42b3ac18e..75b9d0cb1 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/_webhook-settings.tsx
@@ -21,6 +21,7 @@ import {
testWebhook,
type WebhookTestResult,
} from '@/lib/actions/content';
+import { useUserRole } from '@/hooks/use-user-role';
import { toast } from 'sonner';
const WEBHOOK_EVENTS = [
@@ -45,6 +46,10 @@ interface WebhookSettingsDialogProps {
export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSettingsDialogProps) {
const t = useTranslations('content.webhook');
const tFailure = useTranslations('apiFailure');
+ // Only admins and managers save the webhook (RLS) and test it (the API):
+ // a member sees it, and why it can't be changed, before pressing anything.
+ const { canManage } = useUserRole();
+ const readOnly = !canManage;
const [url, setUrl] = useState('');
const [secret, setSecret] = useState('');
@@ -154,6 +159,11 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
</div>
) : (
<div className="space-y-4">
+ {readOnly && (
+ <p className="rounded-md border bg-muted/40 p-3 text-xs text-muted-foreground">
+ {t('readOnly')}
+ </p>
+ )}
<div className="space-y-2">
<Label htmlFor="webhook-url">{t('url')}</Label>
<Input
@@ -162,6 +172,7 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
placeholder={t('urlPlaceholder')}
value={url}
onChange={(e) => setUrl(e.target.value)}
+ disabled={readOnly}
/>
</div>
@@ -173,6 +184,7 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
placeholder={t('secretPlaceholder')}
value={secret}
onChange={(e) => setSecret(e.target.value)}
+ disabled={readOnly}
/>
</div>
@@ -185,6 +197,7 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
<Checkbox
id={`webhook-event-${eventOption.value}`}
checked={events.includes(eventOption.value)}
+ disabled={readOnly}
onCheckedChange={(checked) =>
setEvents((current) =>
checked === true
@@ -214,8 +227,9 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
type="button"
role="switch"
aria-checked={isActive}
+ disabled={readOnly}
onClick={() => setIsActive(!isActive)}
- className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors ${
+ className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
isActive ? 'bg-primary' : 'bg-muted'
}`}
>
@@ -250,7 +264,7 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
variant="outline"
size="sm"
onClick={handleTest}
- disabled={testing || !url.trim()}
+ disabled={readOnly || testing || !url.trim()}
className="gap-2"
>
{testing && <LoadingDots />}
@@ -259,7 +273,7 @@ export function WebhookSettingsDialog({ open, onOpenChange, brandId }: WebhookSe
<Button
size="sm"
onClick={handleSave}
- disabled={saving || !url.trim()}
+ disabled={readOnly || saving || !url.trim()}
className="gap-2"
>
{saving && <LoadingDots />}