fix(api): preserve omitted client fields in partial updates (#7042)

Keep omitted client fields and per-inbound flows unchanged while honoring explicit clears. Support the query aliases used to recover legacy dot-name clients and regenerate the API reference. Add an HTTP regression covering partial updates through those aliases.
This commit is contained in:
Aleksey Fedorov
2026-11-06 03:06:16 +10:00
committed by GitHub
parent cd176faf4e
commit e4935be861
14 changed files with 525 additions and 71 deletions
+4 -4
View File
@@ -1276,9 +1276,9 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/clients/update/:email',
summary:
'Update an existing client by email. Changes propagate to every attached inbound. Body is the JSON client payload — supply the full set of fields you want to keep (the server replaces the row, it does not patch).',
'Update an existing client by email. Changes propagate to every attached inbound. Body is the JSON client payload: omitted fields keep their current values, and an explicit zero, empty or null value clears a field, except as noted below.',
description:
'The inbounds are applied concurrently and independently: one that fails no longer stops the others. Every inbound error names the inbound it came from (`inbound 7: <message>`), and several failures are reported together, one per line. So a `success:false` response can still have applied the edit to the remaining inbounds. The client record is written after the inbounds, so a failure there is reported without an `inbound <id>:` prefix and leaves the inbound edits in place.',
'An omitted `flow` leaves every attached inbound on its own flow. Send `"reverse": null` to remove the reverse tag. Credentials (`id`, `password`, `auth`, `secret`, `subId`) and WireGuard/AmneziaWG `allowedIPs` are never cleared: an empty value keeps the stored one. The inbounds are applied concurrently and independently: one that fails no longer stops the others. Every inbound error names the inbound it came from (`inbound 7: <message>`), and several failures are reported together, one per line. So a `success:false` response can still have applied the edit to the remaining inbounds. The client record is written after the inbounds, so a failure there is reported without an `inbound <id>:` prefix and leaves the inbound edits in place.',
params: [
{
name: 'email',
@@ -1294,9 +1294,9 @@ export const sections: readonly Section[] = [
method: 'POST',
path: '/panel/api/clients/update',
summary:
'Update an existing client by email. Changes propagate to every attached inbound. Body is the JSON client payload — supply the full set of fields you want to keep (the server replaces the row, it does not patch).',
'Update an existing client by email. Changes propagate to every attached inbound. Body is the JSON client payload: omitted fields keep their current values, and an explicit zero, empty or null value clears a field, except as noted below.',
description:
'Query-parameter alias for the path endpoint. Use email=. or email=.. to manage legacy reserved names without URL dot-segment normalization. The inbounds are applied concurrently and independently: one that fails no longer stops the others. Every inbound error names the inbound it came from (`inbound 7: <message>`), and several failures are reported together, one per line. So a `success:false` response can still have applied the edit to the remaining inbounds. The client record is written after the inbounds, so a failure there is reported without an `inbound <id>:` prefix and leaves the inbound edits in place.',
'Query-parameter alias for the path endpoint. Use email=. or email=.. to manage legacy reserved names without URL dot-segment normalization. An omitted `flow` leaves every attached inbound on its own flow. Send `"reverse": null` to remove the reverse tag. Credentials (`id`, `password`, `auth`, `secret`, `subId`) and WireGuard/AmneziaWG `allowedIPs` are never cleared: an empty value keeps the stored one. The inbounds are applied concurrently and independently: one that fails no longer stops the others. Every inbound error names the inbound it came from (`inbound 7: <message>`), and several failures are reported together, one per line. So a `success:false` response can still have applied the edit to the remaining inbounds. The client record is written after the inbounds, so a failure there is reported without an `inbound <id>:` prefix and leaves the inbound edits in place.',
params: [
{
name: 'email',
@@ -798,10 +798,10 @@ export default function ClientFormModal({
comment: values.comment,
enable: !!values.enable,
};
// Sent even when empty, so clearing the tag never rests on how the server
// reads an omitted key.
const reverseTagValue = showReverseTag ? (values.reverseTag || '').trim() : '';
if (reverseTagValue) {
clientPayload.reverse = { tag: reverseTagValue };
}
clientPayload.reverse = reverseTagValue ? { tag: reverseTagValue } : null;
if (showWireguard || showAmneziawg) {
// AmneziaWG peers are wire-identical to WireGuard peers (same
@@ -0,0 +1,64 @@
import { describe, it, expect, vi } from 'vitest';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ThemeProvider } from '@/hooks/useTheme';
import ClientFormModal from '@/pages/clients/ClientFormModal';
import type { ClientRecord, InboundOption } from '@/hooks/useClients';
const VLESS_INBOUND = {
id: 7,
port: 10443,
protocol: 'vless',
tag: 'in-10443-tcp',
enable: true,
} as unknown as InboundOption;
const CLIENT = {
email: 'reverse-user',
uuid: '11111111-1111-1111-1111-111111111111',
subId: 'subid-reverse',
enable: true,
reverse: { tag: 'back' },
} as unknown as ClientRecord;
async function saveEdited(edit?: (input: HTMLInputElement) => void) {
const save = vi.fn().mockResolvedValue({ success: true });
render(
<ThemeProvider>
<QueryClientProvider
client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}
>
<ClientFormModal
open
mode="edit"
client={CLIENT}
inbounds={[VLESS_INBOUND]}
attachedIds={[7]}
save={save}
onOpenChange={() => {}}
/>
</QueryClientProvider>
</ThemeProvider>,
);
const input = (await screen.findByPlaceholderText('Optional reverse tag')) as HTMLInputElement;
await waitFor(() => expect(input.value).toBe('back'));
edit?.(input);
fireEvent.click(await screen.findByRole('button', { name: /save/i }));
await waitFor(() => expect(save).toHaveBeenCalled());
return save.mock.calls[0][0] as Record<string, unknown>;
}
// A cleared tag goes out as an explicit null rather than a missing key, which a
// partial update would read as "keep the stored tag".
describe('ClientFormModal — reverse tag', () => {
it('sends an explicit null when the operator clears the tag', async () => {
const payload = await saveEdited((input) => fireEvent.change(input, { target: { value: '' } }));
expect(payload).toHaveProperty('reverse', null);
});
it('round-trips an unchanged tag', async () => {
const payload = await saveEdited();
expect(payload.reverse).toEqual({ tag: 'back' });
});
});