fix(webhook): scope_filter Hibernate ordinal bug + UI toggle для active

Два бага в /webhooks (user report):

1. **500 при выборе scope в форме**

POST /admin/webhooks/subscriptions с scopeFilter:["PUBLIC"] возвращал 500.

Root cause: WebhookSubscription.scopeFilter был List<DataScope> с
@JdbcTypeCode(SqlTypes.ARRAY). Hibernate сериализовал enum в TEXT[] как
ordinal (е.g. {0} для PUBLIC), а DB CHECK constraint
chk_webhook_scope_filter ожидает строковые имена. Insert падал
DataIntegrityViolationException → 500.

Fix: field теперь List<String> (raw enum names). Getter/setter
конвертируют в/из DataScope — API surface (DTO, service signatures,
WebhookDispatcher) не меняется.

2. **Нет toggle active/inactive в UI**

useUpdateWebhook hook был, но не использовался в UI. Status показывался
только read-only badge'ом. Невозможно деактивировать webhook через UI.

Fix: добавлен toggle button рядом с Status badge на /webhooks/:id.
Sends PUT с inverted active flag (backend treats PUT как full replace,
поэтому пересобираем full payload).

i18n: 'webhooks.action.activate' / 'deactivate' default labels (RU).
This commit is contained in:
Zimin A.N.
2026-05-13 14:02:35 +03:00
parent 4bdc7d2245
commit d4ee30a7dd
2 changed files with 57 additions and 7 deletions
+34 -3
View File
@@ -33,6 +33,7 @@ import {
useRetryWebhookDelivery,
useRotateWebhookSecret,
useTestWebhook,
useUpdateWebhook,
} from '@/api/mutations'
import type { WebhookTestPingResult } from '@/api/client'
import { SCOPE_DOT } from '@/lib/scope-style'
@@ -63,6 +64,7 @@ function WebhookDetailPage() {
}
const rotateMut = useRotateWebhookSecret()
const deleteMut = useDeleteWebhook()
const updateMut = useUpdateWebhook()
const retryMut = useRetryWebhookDelivery()
const testMut = useTestWebhook()
const [testResult, setTestResult] = useState<WebhookTestPingResult | null>(null)
@@ -161,9 +163,38 @@ function WebhookDetailPage() {
<code className="text-mono break-all">{data.url}</code>
</InfoRow>
<InfoRow label={t('webhooks.col.status')}>
<Badge variant={data.active ? 'success' : 'neutral'}>
{data.active ? t('webhooks.active') : t('webhooks.inactive')}
</Badge>
<div className="flex items-center gap-3">
<Badge variant={data.active ? 'success' : 'neutral'}>
{data.active ? t('webhooks.active') : t('webhooks.inactive')}
</Badge>
<button
type="button"
onClick={() => {
// Toggle active. PUT requires full payload — пересобираем
// из current state + переворачиваем active. Backend
// service treats PUT как full replace, поэтому все
// поля должны быть переданы.
updateMut.mutate({
id: data.id,
payload: {
name: data.name,
url: data.url,
scopeFilter: data.scopeFilter ?? undefined,
dictionaryFilter: data.dictionaryFilter ?? undefined,
eventTypeFilter: data.eventTypeFilter ?? undefined,
description: data.description ?? undefined,
active: !data.active,
},
})
}}
disabled={updateMut.isPending}
className="text-cap text-accent hover:underline disabled:opacity-50"
>
{data.active
? t('webhooks.action.deactivate', { defaultValue: 'Деактивировать' })
: t('webhooks.action.activate', { defaultValue: 'Активировать' })}
</button>
</div>
</InfoRow>
<InfoRow label={t('webhooks.field.scopeFilter')}>
{data.scopeFilter && data.scopeFilter.length > 0 ? (