Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Preserve refused audit webhook drafts and make phone entry usable

pulse-triage[bot]49efecdeb15a
diff --git a/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx b/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
index 895fc5bb34..5e66189731 100644
--- a/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
+++ b/frontend-modern/src/components/Settings/AuditWebhookPanel.tsx
@@ -126,7 +126,7 @@ export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
</div>
<button
onClick={() => setUrlToRemove(url)}
- disabled={!canManage()}
+ disabled={!canManage() || saving()}
class="p-2 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/25 rounded-md transition-colors"
title="Remove webhook endpoint"
>
@@ -145,12 +145,13 @@ export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
</Show>
</div>
</Show>
- <div class="flex gap-3 pt-4 border-t border-border">
+ <div class="flex flex-col gap-3 pt-4 border-t border-border sm:flex-row">
<input
ref={newUrlInputRef}
type="text"
+ aria-label="Audit webhook URL"
placeholder="https://your-api.com/webhook"
- class={`${formControl} flex-1`}
+ class={`${formControl} w-full min-w-0 flex-1`}
value={newUrl()}
onInput={(e) => setNewUrl(e.currentTarget.value)}
onKeyDown={(e) => e.key === 'Enter' && handleAddWebhook()}
@@ -159,7 +160,7 @@ export const AuditWebhookPanel: Component<AuditWebhookPanelProps> = (props) => {
<button
onClick={handleAddWebhook}
disabled={!canManage() || saving() || !newUrl().trim()}
- class="px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed text-white rounded-md flex items-center gap-2 transition-colors"
+ class="px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed text-white rounded-md flex items-center justify-center gap-2 transition-colors sm:shrink-0"
>
<Plus size={18} />
Add Endpoint
diff --git a/frontend-modern/src/components/Settings/__tests__/AuditWebhookPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/AuditWebhookPanel.test.tsx
new file mode 100644
index 0000000000..3f3040ac62
--- /dev/null
+++ b/frontend-modern/src/components/Settings/__tests__/AuditWebhookPanel.test.tsx
@@ -0,0 +1,122 @@
+import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { AuditWebhookPanel } from '../AuditWebhookPanel';
+
+const apiFetchJSON = vi.fn();
+const showSuccess = vi.fn();
+const showWarning = vi.fn();
+const existingUrl = 'https://existing.example.test/events';
+const addedUrl = 'https://new.example.test/events';
+
+vi.mock('@/utils/apiClient', () => ({
+ apiFetchJSON: (...args: unknown[]) => apiFetchJSON(...args),
+}));
+vi.mock('@/utils/toast', () => ({
+ showSuccess: (...args: unknown[]) => showSuccess(...args),
+ showWarning: (...args: unknown[]) => showWarning(...args),
+}));
+vi.mock('@/utils/logger', () => ({ logger: { error: vi.fn() } }));
+vi.mock('@/stores/license', () => ({
+ getRuntimeCapabilityBlock: () => undefined,
+ hasFeature: () => true,
+ loadRuntimeCapabilities: vi.fn().mockResolvedValue(undefined),
+}));
+vi.mock('@/stores/licenseCommercial', () => ({
+ getUpgradeActionDestination: () => ({ href: '/upgrade', external: false }),
+}));
+vi.mock('@/stores/sessionPresentationPolicy', () => ({
+ presentationPolicyHidesUpgradePrompts: () => false,
+}));
+
+const writeCalls = () => apiFetchJSON.mock.calls.filter(([, options]) => options?.method === 'POST');
+const openPanel = async (canManage = true) => {
+ render(() => <AuditWebhookPanel canManage={canManage} />);
+ await screen.findByText(existingUrl);
+ return screen.getByRole('textbox', { name: 'Audit webhook URL' });
+};
+
+beforeEach(() => {
+ apiFetchJSON.mockReset().mockResolvedValue({ urls: [existingUrl] });
+ showSuccess.mockReset();
+ showWarning.mockReset();
+});
+afterEach(cleanup);
+
+describe('audit webhook entry recovery', () => {
+ it('preserves a refused entry and old destinations, then clears only after a successful retry', async () => {
+ const input = await openPanel();
+ apiFetchJSON.mockRejectedValueOnce(new Error('save refused')).mockResolvedValueOnce({});
+ fireEvent.input(input, { target: { value: ` ${addedUrl} ` } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ await waitFor(() => expect(showWarning).toHaveBeenCalledWith('Failed to save webhook configuration'));
+ expect(input).toHaveValue(` ${addedUrl} `);
+ expect(screen.getByText(existingUrl)).toBeInTheDocument();
+ expect(screen.queryByText(addedUrl)).not.toBeInTheDocument();
+ expect(showSuccess).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Add Endpoint' }));
+ await screen.findByText(addedUrl);
+ expect(input).toHaveValue('');
+ expect(showSuccess).toHaveBeenCalledOnce();
+ expect(writeCalls().map(([, options]) => JSON.parse(options.body))).toEqual([
+ { urls: [existingUrl, addedUrl] },
+ { urls: [existingUrl, addedUrl] },
+ ]);
+ });
+
+ it('keeps a newer draft and rejects concurrent Enter/removal writes during a pending save', async () => {
+ const input = await openPanel();
+ let finishSave!: (value: object) => void;
+ apiFetchJSON.mockReturnValueOnce(new Promise((resolve) => { finishSave = resolve; }));
+ fireEvent.input(input, { target: { value: addedUrl } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Add Endpoint' })).toBeDisabled());
+ expect(screen.getByRole('button', { name: 'Remove webhook endpoint' })).toBeDisabled();
+ fireEvent.input(input, { target: { value: 'https://next.example.test/events' } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ expect(writeCalls()).toHaveLength(1);
+ finishSave({});
+ await screen.findByText(addedUrl);
+ expect(input).toHaveValue('https://next.example.test/events');
+ expect(screen.getByRole('button', { name: 'Add Endpoint' })).toBeEnabled();
+ });
+
+ it('requires explicit removal and retains the endpoint and draft after a refused removal', async () => {
+ const input = await openPanel();
+ fireEvent.input(input, { target: { value: addedUrl } });
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook endpoint' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+ expect(writeCalls()).toHaveLength(0);
+ expect(screen.getByText(existingUrl)).toBeInTheDocument();
+
+ apiFetchJSON.mockRejectedValueOnce(new Error('save refused')).mockResolvedValueOnce({});
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook endpoint' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook' }));
+ await waitFor(() => expect(showWarning).toHaveBeenCalledOnce());
+ expect(screen.getByText(existingUrl)).toBeInTheDocument();
+ expect(input).toHaveValue(addedUrl);
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook endpoint' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Remove webhook' }));
+ await waitFor(() => expect(screen.queryByText(existingUrl)).not.toBeInTheDocument());
+ expect(input).toHaveValue(addedUrl);
+ expect(writeCalls().map(([, options]) => JSON.parse(options.body))).toEqual([{ urls: [] }, { urls: [] }]);
+ });
+
+ it.each(['not a URL', existingUrl])('does not write an invalid or duplicate entry: %s', async (draft) => {
+ const input = await openPanel();
+ fireEvent.input(input, { target: { value: draft } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ expect(showWarning).toHaveBeenCalledOnce();
+ expect(writeCalls()).toHaveLength(0);
+ expect(input).toHaveValue(draft);
+ });
+
+ it('does not allow a read-only account to write through Enter or removal', async () => {
+ const input = await openPanel(false);
+ expect(input).toBeDisabled();
+ expect(screen.getByRole('button', { name: 'Add Endpoint' })).toBeDisabled();
+ expect(screen.getByRole('button', { name: 'Remove webhook endpoint' })).toBeDisabled();
+ fireEvent.keyDown(input, { key: 'Enter' });
+ expect(writeCalls()).toHaveLength(0);
+ });
+});
diff --git a/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts b/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
index 64cc7627ff..2bfa16d2a4 100644
--- a/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
+++ b/frontend-modern/src/components/Settings/useAuditWebhookPanelState.ts
@@ -53,17 +53,20 @@ export const useAuditWebhookPanelState = (canManageOverride?: boolean) => {
});
setWebhookUrls(urls);
showSuccess(getAuditWebhookSaveSuccessMessage());
+ return true;
} catch (error) {
logger.error('[AuditWebhookPanel] Failed to save audit webhooks', error);
showWarning(getAuditWebhookSaveErrorMessage());
+ return false;
} finally {
setSaving(false);
}
};
const handleAddWebhook = async () => {
- if (!canManage()) return;
- const url = newUrl().trim();
+ if (!canManage() || saving()) return;
+ const draft = newUrl();
+ const url = draft.trim();
if (!url) return;
try {
@@ -78,12 +81,14 @@ export const useAuditWebhookPanelState = (canManageOverride?: boolean) => {
return;
}
- await saveWebhooks([...webhookUrls(), url]);
- setNewUrl('');
+ const saved = await saveWebhooks([...webhookUrls(), url]);
+ // Leave failed entries available for correction/retry, and do not erase
+ // a different draft typed while the submitted entry was saving.
+ if (saved && newUrl() === draft) setNewUrl('');
};
const handleRemoveWebhook = async (url: string) => {
- if (!canManage()) return;
+ if (!canManage() || saving()) return;
await saveWebhooks(webhookUrls().filter((existingUrl) => existingUrl !== url));
};