diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a80719556..381156ef7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,12 +156,12 @@ jobs: - name: PostgreSQL schema and migration tests run: | set -o pipefail - go test ./internal/database -run '^(TestHostAutoMigrateCreatesColumns_Postgres|TestMigrate_Postgres|TestClientWeeklyRenewMigration_Postgres|TestMigrate_LegacyBooleanVerifyPeerCertByNameIsBlanked_Postgres|TestClientKeepAlivePostgresMigrationPreservesLegacyScalars|TestPostgresModelSettled_TracksSchemaPresence)$' -count=1 -v | tee /tmp/postgres-schema.log + go test ./internal/database -run '^(TestHostAutoMigrateCreatesColumns_Postgres|TestMigrate_Postgres|TestClientWeeklyRenewMigration_Postgres|TestMigrate_LegacyBooleanVerifyPeerCertByNameIsBlanked_Postgres|TestClientKeepAlivePostgresMigrationPreservesLegacyScalars|TestPostgresModelSettled_TracksSchemaPresence|TestEnsureClientGroupRows_Postgres)$' -count=1 -v | tee /tmp/postgres-schema.log # All must pass. Counting, not SKIP-matching: renaming a test would # otherwise leave this step green while testing nothing. passed=$(grep -c -- '^--- PASS' /tmp/postgres-schema.log || true) - if [ "$passed" -lt 6 ]; then - echo "expected at least 6 passing PostgreSQL schema tests, got $passed" >&2 + if [ "$passed" -lt 7 ]; then + echo "expected at least 7 passing PostgreSQL schema tests, got $passed" >&2 exit 1 fi diff --git a/docs/content/docs/en/reference/api/clients.mdx b/docs/content/docs/en/reference/api/clients.mdx index 4194b8a0b..eae5f2d48 100644 --- a/docs/content/docs/en/reference/api/clients.mdx +++ b/docs/content/docs/en/reference/api/clients.mdx @@ -228,27 +228,36 @@ _openapi: clients. url: '#zero-updown-counters-for-many-clients-in-one-call-loops-the-single-reset-path-so-each-client-its-quota-had-disabled-is-re-enabled-across-its-attached-inbounds-and-pushed-to-xrayremote-nodes-a-client-disabled-by-hand-stays-disabled-returns-the-count-of-successfully-reset-clients' - depth: 2 - title: List all client groups with their member counts. Merges persisted groups - (rows in client_groups, including empty placeholders) with the distinct - group_name values currently set on clients. Sorted alphabetically - (case-insensitive). - url: '#list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive' + title: List all client groups with their member counts and the host groups bound + to each. Merges persisted groups (rows in client_groups, including empty + placeholders) with the distinct group_name values currently set on + clients. Sorted alphabetically (case-insensitive). + url: '#list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive' + - depth: 2 + title: Replace the host groups attached to a client group. Clients in this group + receive the bound host groups instead of the inbound default host pool; + other clients are unaffected. An empty array clears the bindings. + Returns the saved host group IDs. + url: '#replace-the-host-groups-attached-to-a-client-group-clients-in-this-group-receive-the-bound-host-groups-instead-of-the-inbound-default-host-pool-other-clients-are-unaffected-an-empty-array-clears-the-bindings-returns-the-saved-host-group-ids' - depth: 2 title: Return just the email list of clients that currently belong to the given group. Useful for fanning a single bulk action over an entire group without round-tripping the full client list. url: '#return-just-the-email-list-of-clients-that-currently-belong-to-the-given-group-useful-for-fanning-a-single-bulk-action-over-an-entire-group-without-round-tripping-the-full-client-list' - depth: 2 - title: Create a new empty (placeholder) group. The group becomes selectable in - client forms and the filter drawer even before any client is added to - it. Errors if a group with the same name already exists. - url: '#create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists' + title: Create a new group, optionally with host rules bound to it. The group + becomes selectable in client forms and the filter drawer even before any + client is added to it. Host group IDs are validated before the group is + created. Errors if a group with the same name already exists. + url: '#create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists' - depth: 2 - title: Rename a group. The new name is applied to the client_groups row AND - propagated to every matching client (both clients.group_name and the - client entry inside every owning inbound's settings JSON) in a single - transaction. Returns the number of clients whose label was updated. - url: '#rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated' + title: Rename a group and optionally replace its host rules in one transaction. + The new name is applied to the client_groups row AND propagated to every + matching client (both clients.group_name and the client entry inside + every owning inbound's settings JSON). Omit hostGroupIds to leave the + bindings unchanged; send an empty array to clear them. Returns the + number of clients whose label was updated. + url: '#rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated' - depth: 2 title: Remove a group. Deletes the client_groups row and clears the group label from every matching client (both clients.group_name and the inbound @@ -562,24 +571,32 @@ _openapi: disabled by hand stays disabled. Returns the count of successfully reset clients. id: zero-updown-counters-for-many-clients-in-one-call-loops-the-single-reset-path-so-each-client-its-quota-had-disabled-is-re-enabled-across-its-attached-inbounds-and-pushed-to-xrayremote-nodes-a-client-disabled-by-hand-stays-disabled-returns-the-count-of-successfully-reset-clients - - content: List all client groups with their member counts. Merges persisted - groups (rows in client_groups, including empty placeholders) with the - distinct group_name values currently set on clients. Sorted - alphabetically (case-insensitive). - id: list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + - content: List all client groups with their member counts and the host groups + bound to each. Merges persisted groups (rows in client_groups, + including empty placeholders) with the distinct group_name values + currently set on clients. Sorted alphabetically (case-insensitive). + id: list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + - content: Replace the host groups attached to a client group. Clients in this + group receive the bound host groups instead of the inbound default + host pool; other clients are unaffected. An empty array clears the + bindings. Returns the saved host group IDs. + id: replace-the-host-groups-attached-to-a-client-group-clients-in-this-group-receive-the-bound-host-groups-instead-of-the-inbound-default-host-pool-other-clients-are-unaffected-an-empty-array-clears-the-bindings-returns-the-saved-host-group-ids - content: Return just the email list of clients that currently belong to the given group. Useful for fanning a single bulk action over an entire group without round-tripping the full client list. id: return-just-the-email-list-of-clients-that-currently-belong-to-the-given-group-useful-for-fanning-a-single-bulk-action-over-an-entire-group-without-round-tripping-the-full-client-list - - content: Create a new empty (placeholder) group. The group becomes selectable in - client forms and the filter drawer even before any client is added to - it. Errors if a group with the same name already exists. - id: create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists - - content: Rename a group. The new name is applied to the client_groups row AND + - content: Create a new group, optionally with host rules bound to it. The group + becomes selectable in client forms and the filter drawer even before + any client is added to it. Host group IDs are validated before the + group is created. Errors if a group with the same name already exists. + id: create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists + - content: Rename a group and optionally replace its host rules in one + transaction. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the - client entry inside every owning inbound's settings JSON) in a single - transaction. Returns the number of clients whose label was updated. - id: rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + client entry inside every owning inbound's settings JSON). Omit + hostGroupIds to leave the bindings unchanged; send an empty array to + clear them. Returns the number of clients whose label was updated. + id: rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - content: Remove a group. Deletes the client_groups row and clears the group label from every matching client (both clients.group_name and the inbound settings JSON). The clients themselves are NOT deleted — use @@ -866,7 +883,7 @@ export default function Layout(props) { return ( <> {props.children} - + ); } \ No newline at end of file diff --git a/docs/content/docs/fa/reference/api/clients.mdx b/docs/content/docs/fa/reference/api/clients.mdx index ef08359ca..0d8523ff1 100644 --- a/docs/content/docs/fa/reference/api/clients.mdx +++ b/docs/content/docs/fa/reference/api/clients.mdx @@ -216,7 +216,7 @@ _openapi: group_name values currently set on clients. Sorted alphabetically (case-insensitive). url: >- - #list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + #list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - depth: 2 title: >- Return just the email list of clients that currently belong to the given @@ -230,7 +230,7 @@ _openapi: client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists. url: >- - #create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + #create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - depth: 2 title: >- Rename a group. The new name is applied to the client_groups row AND @@ -238,7 +238,7 @@ _openapi: client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated. url: >- - #rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + #rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - depth: 2 title: >- Remove a group. Deletes the client_groups row and clears the group label @@ -514,7 +514,7 @@ _openapi: distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive). id: >- - list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - content: >- Return just the email list of clients that currently belong to the given group. Useful for fanning a single bulk action over an entire @@ -526,14 +526,14 @@ _openapi: in client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists. id: >- - create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - content: >- Rename a group. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated. id: >- - rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - content: >- Remove a group. Deletes the client_groups row and clears the group label from every matching client (both clients.group_name and the diff --git a/docs/content/docs/ru/reference/api/clients.mdx b/docs/content/docs/ru/reference/api/clients.mdx index 7d8dd6ff9..e6bbf9bcf 100644 --- a/docs/content/docs/ru/reference/api/clients.mdx +++ b/docs/content/docs/ru/reference/api/clients.mdx @@ -216,7 +216,7 @@ _openapi: group_name values currently set on clients. Sorted alphabetically (case-insensitive). url: >- - #list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + #list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - depth: 2 title: >- Return just the email list of clients that currently belong to the given @@ -230,7 +230,7 @@ _openapi: client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists. url: >- - #create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + #create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - depth: 2 title: >- Rename a group. The new name is applied to the client_groups row AND @@ -238,7 +238,7 @@ _openapi: client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated. url: >- - #rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + #rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - depth: 2 title: >- Remove a group. Deletes the client_groups row and clears the group label @@ -514,7 +514,7 @@ _openapi: distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive). id: >- - list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - content: >- Return just the email list of clients that currently belong to the given group. Useful for fanning a single bulk action over an entire @@ -526,14 +526,14 @@ _openapi: in client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists. id: >- - create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - content: >- Rename a group. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated. id: >- - rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - content: >- Remove a group. Deletes the client_groups row and clears the group label from every matching client (both clients.group_name and the diff --git a/docs/content/docs/zh/reference/api/clients.mdx b/docs/content/docs/zh/reference/api/clients.mdx index bfbb1b6ad..aa9eda9c2 100644 --- a/docs/content/docs/zh/reference/api/clients.mdx +++ b/docs/content/docs/zh/reference/api/clients.mdx @@ -175,7 +175,7 @@ _openapi: 列出所有客户端分组及其成员数量。将持久化分组(client_groups 中的记录,包括空占位符) 与当前在客户端上设置的去重后的 group_name 值合并。按字母顺序排序(不区分大小写)。 url: >- - #list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + #list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - depth: 2 title: >- 仅返回当前属于指定分组的客户端 email 列表。适用于将单个批量操作扇出到整个分组,而无需 @@ -187,14 +187,14 @@ _openapi: 创建一个新的空(占位)分组。即使尚未向其添加任何客户端,该分组也会在客户端表单和筛选 抽屉中变为可选。若已存在同名分组,则报错。 url: >- - #create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + #create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - depth: 2 title: >- 重命名分组。新名称会应用到 client_groups 记录,并在单个事务中传播到每个匹配的客户端 (包括 clients.group_name 以及每个所属入站的 settings JSON 内的客户端条目)。返回 标签被更新的客户端数量。 url: >- - #rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + #rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - depth: 2 title: >- 移除分组。删除 client_groups 记录,并从每个匹配的客户端清除分组标签(包括 @@ -412,7 +412,7 @@ _openapi: 列出所有客户端分组及其成员数量。将持久化分组(client_groups 中的记录,包括空占位符) 与当前在客户端上设置的去重后的 group_name 值合并。按字母顺序排序(不区分大小写)。 id: >- - list-all-client-groups-with-their-member-counts-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive + list-all-client-groups-with-their-member-counts-and-the-host-groups-bound-to-each-merges-persisted-groups-rows-in-client_groups-including-empty-placeholders-with-the-distinct-group_name-values-currently-set-on-clients-sorted-alphabetically-case-insensitive - content: >- 仅返回当前属于指定分组的客户端 email 列表。适用于将单个批量操作扇出到整个分组,而无需 往返获取完整的客户端列表。 @@ -422,13 +422,13 @@ _openapi: 创建一个新的空(占位)分组。即使尚未向其添加任何客户端,该分组也会在客户端表单和筛选 抽屉中变为可选。若已存在同名分组,则报错。 id: >- - create-a-new-empty-placeholder-group-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-errors-if-a-group-with-the-same-name-already-exists + create-a-new-group-optionally-with-host-rules-bound-to-it-the-group-becomes-selectable-in-client-forms-and-the-filter-drawer-even-before-any-client-is-added-to-it-host-group-ids-are-validated-before-the-group-is-created-errors-if-a-group-with-the-same-name-already-exists - content: >- 重命名分组。新名称会应用到 client_groups 记录,并在单个事务中传播到每个匹配的客户端 (包括 clients.group_name 以及每个所属入站的 settings JSON 内的客户端条目)。返回 标签被更新的客户端数量。 id: >- - rename-a-group-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-in-a-single-transaction-returns-the-number-of-clients-whose-label-was-updated + rename-a-group-and-optionally-replace-its-host-rules-in-one-transaction-the-new-name-is-applied-to-the-client_groups-row-and-propagated-to-every-matching-client-both-clientsgroup_name-and-the-client-entry-inside-every-owning-inbounds-settings-json-omit-hostgroupids-to-leave-the-bindings-unchanged-send-an-empty-array-to-clear-them-returns-the-number-of-clients-whose-label-was-updated - content: >- 移除分组。删除 client_groups 记录,并从每个匹配的客户端清除分组标签(包括 clients.group_name 以及入站 settings JSON)。客户端本身不会被删除——如需删除请先按 diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 4781420a0..9d86bced4 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -11801,7 +11801,7 @@ "tags": [ "Clients" ], - "summary": "List all client groups with their member counts. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).", + "summary": "List all client groups with their member counts and the host groups bound to each. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).", "operationId": "get_panel_api_clients_groups", "responses": { "200": { @@ -11824,12 +11824,18 @@ "success": true, "obj": [ { + "id": 1, "name": "customer-a", - "clientCount": 5 + "clientCount": 5, + "hostGroupIds": [ + "cdn-front" + ] }, { + "id": 2, "name": "internal", - "clientCount": 0 + "clientCount": 0, + "hostGroupIds": [] } ] } @@ -11839,6 +11845,70 @@ } } }, + "/panel/api/clients/groups/{name}/hosts": { + "post": { + "tags": [ + "Clients" + ], + "summary": "Replace the host groups attached to a client group. Clients in this group receive the bound host groups instead of the inbound default host pool; other clients are unaffected. An empty array clears the bindings. Returns the saved host group IDs.", + "operationId": "post_panel_api_clients_groups_name_hosts", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "description": "Group name (URL-encoded).", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object" + }, + "example": { + "hostGroupIds": [ + "cdn-front" + ] + } + } + } + }, + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + }, + "example": { + "success": true, + "obj": { + "hostGroupIds": [ + "cdn-front" + ] + } + } + } + } + } + } + } + }, "/panel/api/clients/groups/{name}/emails": { "get": { "tags": [ @@ -11893,7 +11963,7 @@ "tags": [ "Clients" ], - "summary": "Create a new empty (placeholder) group. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists.", + "summary": "Create a new group, optionally with host rules bound to it. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Host group IDs are validated before the group is created. Errors if a group with the same name already exists.", "operationId": "post_panel_api_clients_groups_create", "requestBody": { "required": true, @@ -11903,7 +11973,10 @@ "type": "object" }, "example": { - "name": "customer-a" + "name": "customer-a", + "hostGroupIds": [ + "cdn-front" + ] } } } @@ -11942,7 +12015,7 @@ "tags": [ "Clients" ], - "summary": "Rename a group. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated.", + "summary": "Rename a group and optionally replace its host rules in one transaction. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON). Omit hostGroupIds to leave the bindings unchanged; send an empty array to clear them. Returns the number of clients whose label was updated.", "operationId": "post_panel_api_clients_groups_rename", "requestBody": { "required": true, @@ -11953,7 +12026,10 @@ }, "example": { "oldName": "customer-a", - "newName": "tier-1" + "newName": "tier-1", + "hostGroupIds": [ + "cdn-front" + ] } } } diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 4781420a0..9d86bced4 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -11801,7 +11801,7 @@ "tags": [ "Clients" ], - "summary": "List all client groups with their member counts. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).", + "summary": "List all client groups with their member counts and the host groups bound to each. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).", "operationId": "get_panel_api_clients_groups", "responses": { "200": { @@ -11824,12 +11824,18 @@ "success": true, "obj": [ { + "id": 1, "name": "customer-a", - "clientCount": 5 + "clientCount": 5, + "hostGroupIds": [ + "cdn-front" + ] }, { + "id": 2, "name": "internal", - "clientCount": 0 + "clientCount": 0, + "hostGroupIds": [] } ] } @@ -11839,6 +11845,70 @@ } } }, + "/panel/api/clients/groups/{name}/hosts": { + "post": { + "tags": [ + "Clients" + ], + "summary": "Replace the host groups attached to a client group. Clients in this group receive the bound host groups instead of the inbound default host pool; other clients are unaffected. An empty array clears the bindings. Returns the saved host group IDs.", + "operationId": "post_panel_api_clients_groups_name_hosts", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "description": "Group name (URL-encoded).", + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object" + }, + "example": { + "hostGroupIds": [ + "cdn-front" + ] + } + } + } + }, + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": {} + } + }, + "example": { + "success": true, + "obj": { + "hostGroupIds": [ + "cdn-front" + ] + } + } + } + } + } + } + } + }, "/panel/api/clients/groups/{name}/emails": { "get": { "tags": [ @@ -11893,7 +11963,7 @@ "tags": [ "Clients" ], - "summary": "Create a new empty (placeholder) group. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists.", + "summary": "Create a new group, optionally with host rules bound to it. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Host group IDs are validated before the group is created. Errors if a group with the same name already exists.", "operationId": "post_panel_api_clients_groups_create", "requestBody": { "required": true, @@ -11903,7 +11973,10 @@ "type": "object" }, "example": { - "name": "customer-a" + "name": "customer-a", + "hostGroupIds": [ + "cdn-front" + ] } } } @@ -11942,7 +12015,7 @@ "tags": [ "Clients" ], - "summary": "Rename a group. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated.", + "summary": "Rename a group and optionally replace its host rules in one transaction. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON). Omit hostGroupIds to leave the bindings unchanged; send an empty array to clear them. Returns the number of clients whose label was updated.", "operationId": "post_panel_api_clients_groups_rename", "requestBody": { "required": true, @@ -11953,7 +12026,10 @@ }, "example": { "oldName": "customer-a", - "newName": "tier-1" + "newName": "tier-1", + "hostGroupIds": [ + "cdn-front" + ] } } } diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index b725f84f1..a54db2dc7 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -1702,9 +1702,18 @@ export const sections: readonly Section[] = [ method: 'GET', path: '/panel/api/clients/groups', summary: - 'List all client groups with their member counts. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).', + 'List all client groups with their member counts and the host groups bound to each. Merges persisted groups (rows in client_groups, including empty placeholders) with the distinct group_name values currently set on clients. Sorted alphabetically (case-insensitive).', response: - '{\n "success": true,\n "obj": [\n { "name": "customer-a", "clientCount": 5 },\n { "name": "internal", "clientCount": 0 }\n ]\n}', + '{\n "success": true,\n "obj": [\n { "id": 1, "name": "customer-a", "clientCount": 5, "hostGroupIds": ["cdn-front"] },\n { "id": 2, "name": "internal", "clientCount": 0, "hostGroupIds": [] }\n ]\n}', + }, + { + method: 'POST', + path: '/panel/api/clients/groups/:name/hosts', + summary: + 'Replace the host groups attached to a client group. Clients in this group receive the bound host groups instead of the inbound default host pool; other clients are unaffected. An empty array clears the bindings. Returns the saved host group IDs.', + params: [{ name: 'name', in: 'path', type: 'string', desc: 'Group name (URL-encoded).' }], + body: '{\n "hostGroupIds": ["cdn-front"]\n}', + response: '{\n "success": true,\n "obj": {\n "hostGroupIds": ["cdn-front"]\n }\n}', }, { method: 'GET', @@ -1718,16 +1727,16 @@ export const sections: readonly Section[] = [ method: 'POST', path: '/panel/api/clients/groups/create', summary: - 'Create a new empty (placeholder) group. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Errors if a group with the same name already exists.', - body: '{\n "name": "customer-a"\n}', + 'Create a new group, optionally with host rules bound to it. The group becomes selectable in client forms and the filter drawer even before any client is added to it. Host group IDs are validated before the group is created. Errors if a group with the same name already exists.', + body: '{\n "name": "customer-a",\n "hostGroupIds": ["cdn-front"]\n}', response: '{\n "success": true,\n "obj": {\n "name": "customer-a"\n }\n}', }, { method: 'POST', path: '/panel/api/clients/groups/rename', summary: - "Rename a group. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON) in a single transaction. Returns the number of clients whose label was updated.", - body: '{\n "oldName": "customer-a",\n "newName": "tier-1"\n}', + "Rename a group and optionally replace its host rules in one transaction. The new name is applied to the client_groups row AND propagated to every matching client (both clients.group_name and the client entry inside every owning inbound's settings JSON). Omit hostGroupIds to leave the bindings unchanged; send an empty array to clear them. Returns the number of clients whose label was updated.", + body: '{\n "oldName": "customer-a",\n "newName": "tier-1",\n "hostGroupIds": ["cdn-front"]\n}', response: '{\n "success": true,\n "obj": {\n "affected": 5\n }\n}', }, { diff --git a/frontend/src/pages/groups/GroupHostRulesModal.tsx b/frontend/src/pages/groups/GroupHostRulesModal.tsx new file mode 100644 index 000000000..fe7331559 --- /dev/null +++ b/frontend/src/pages/groups/GroupHostRulesModal.tsx @@ -0,0 +1,63 @@ +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { Modal, Typography } from 'antd'; + +import type { GroupSummary } from '@/schemas/client'; +import HostGroupSelect from './HostGroupSelect'; + +interface GroupHostRulesModalProps { + open: boolean; + group: GroupSummary | null; + onOpenChange: (open: boolean) => void; + save: (name: string, hostGroupIds: string[]) => Promise; +} + +export default function GroupHostRulesModal({ + open, + group, + onOpenChange, + save, +}: GroupHostRulesModalProps) { + const { t } = useTranslation(); + const [loadingSave, setLoadingSave] = useState(false); + const openGroupKey = open ? (group?.name ?? null) : null; + const [syncedGroupKey, setSyncedGroupKey] = useState(openGroupKey); + const [value, setValue] = useState(group?.hostGroupIds ?? []); + + // Reset during render so the first open frame already shows the saved set. + if (openGroupKey !== syncedGroupKey) { + setSyncedGroupKey(openGroupKey); + if (open) { + setValue(group?.hostGroupIds ?? []); + setLoadingSave(false); + } + } + + async function onOk() { + if (!group || loadingSave) return; + setLoadingSave(true); + try { + if (await save(group.name, value)) onOpenChange(false); + } finally { + setLoadingSave(false); + } + } + + return ( + onOpenChange(false)} + destroyOnHidden + > + + {t('pages.groups.hostRulesHint')} + + + + ); +} diff --git a/frontend/src/pages/groups/GroupsPage.tsx b/frontend/src/pages/groups/GroupsPage.tsx index ba49175ab..407785f70 100644 --- a/frontend/src/pages/groups/GroupsPage.tsx +++ b/frontend/src/pages/groups/GroupsPage.tsx @@ -29,6 +29,7 @@ import { EditOutlined, LinkOutlined, MoreOutlined, + PartitionOutlined, PieChartOutlined, PlusOutlined, RetweetOutlined, @@ -56,6 +57,7 @@ import { type GroupSummary, } from '@/schemas/client'; import { parseMsg } from '@/utils/zodValidate'; +import HostGroupSelect from './HostGroupSelect'; const ClientRecordListSchema = z .array(ClientRecordSchema) @@ -66,9 +68,16 @@ const SubLinksModal = lazy(() => import('../clients/SubLinksModal')); const ClientBulkAdjustModal = lazy(() => import('../clients/ClientBulkAdjustModal')); const GroupAddClientsModal = lazy(() => import('./GroupAddClientsModal')); const GroupRemoveClientsModal = lazy(() => import('./GroupRemoveClientsModal')); +const GroupHostRulesModal = lazy(() => import('./GroupHostRulesModal')); const JSON_HEADERS = { headers: { 'Content-Type': 'application/json' } } as const; +function sameIds(a: string[], b: string[]): boolean { + if (a.length !== b.length) return false; + const ids = new Set(a); + return b.every((id) => ids.has(id)); +} + async function fetchGroups(): Promise { const msg = await HttpUtil.get('/panel/api/clients/groups', undefined, { silent: true }); if (!msg?.success) throw new Error(msg?.msg || 'Failed to load groups'); @@ -117,15 +126,15 @@ export default function GroupsPage() { }, [queryClient]); const createMut = useMutation({ - mutationFn: (body: { name: string }) => + mutationFn: (body: { name: string; hostGroupIds: string[] }) => HttpUtil.post('/panel/api/clients/groups/create', body, JSON_HEADERS), onSuccess: (msg) => { if (msg?.success) invalidate(); }, }); - const renameMut = useMutation({ - mutationFn: (body: { oldName: string; newName: string }) => + const editMut = useMutation({ + mutationFn: (body: { oldName: string; newName: string; hostGroupIds: string[] }) => HttpUtil.post('/panel/api/clients/groups/rename', body, JSON_HEADERS), onSuccess: (msg) => { if (msg?.success) invalidate(); @@ -148,14 +157,30 @@ export default function GroupsPage() { }, }); + const groupHostsMut = useMutation({ + mutationFn: (body: { name: string; hostGroupIds: string[] }) => + HttpUtil.post( + `/panel/api/clients/groups/${encodeURIComponent(body.name)}/hosts`, + { hostGroupIds: body.hostGroupIds }, + JSON_HEADERS, + ), + onSuccess: (msg) => { + if (msg?.success) invalidate(); + }, + }); + const [createOpen, setCreateOpen] = useState(false); const [createName, setCreateName] = useState(''); + const [createHostGroupIds, setCreateHostGroupIds] = useState([]); - const [renameOpen, setRenameOpen] = useState(false); - const [renameTarget, setRenameTarget] = useState(null); - const [renameValue, setRenameValue] = useState(''); + const [editOpen, setEditOpen] = useState(false); + const [editTarget, setEditTarget] = useState(null); + const [editName, setEditName] = useState(''); + const [editHostGroupIds, setEditHostGroupIds] = useState([]); const [subLinksOpen, setSubLinksOpen] = useState(false); + const [hostRulesOpen, setHostRulesOpen] = useState(false); + const [hostRulesGroup, setHostRulesGroup] = useState(null); const [adjustOpen, setAdjustOpen] = useState(false); const [addClientsOpen, setAddClientsOpen] = useState(false); const [removeClientsOpen, setRemoveClientsOpen] = useState(false); @@ -189,6 +214,7 @@ export default function GroupsPage() { function openCreate() { setCreateName(''); + setCreateHostGroupIds([]); setCreateOpen(true); } @@ -199,39 +225,50 @@ export default function GroupsPage() { messageApi.error(t('pages.groups.renameCollision', { name })); return; } - const msg = await createMut.mutateAsync({ name }); + const msg = await createMut.mutateAsync({ name, hostGroupIds: createHostGroupIds }); if (msg?.success) { messageApi.success(t('pages.groups.createSuccess', { name })); setCreateOpen(false); } } - function openRename(g: GroupSummary) { - setRenameTarget(g); - setRenameValue(g.name); - setRenameOpen(true); + function openEdit(g: GroupSummary) { + setEditTarget(g); + setEditName(g.name); + setEditHostGroupIds(g.hostGroupIds ?? []); + setEditOpen(true); } - async function confirmRename() { - if (!renameTarget) return; - const next = renameValue.trim(); - if (!next || next === renameTarget.name) { - setRenameOpen(false); - return; - } + async function confirmEdit() { + if (!editTarget) return; + const next = editName.trim(); + if (!next) return; + const nameChanged = next !== editTarget.name; if ( - groups.some( - (g) => g.name.toLowerCase() === next.toLowerCase() && g.name !== renameTarget.name, - ) + nameChanged && + groups.some((g) => g.name !== editTarget.name && g.name.toLowerCase() === next.toLowerCase()) ) { messageApi.error(t('pages.groups.renameCollision', { name: next })); return; } - const msg = await renameMut.mutateAsync({ oldName: renameTarget.name, newName: next }); + const previousHostGroupIds = editTarget.hostGroupIds ?? []; + if (!nameChanged && sameIds(previousHostGroupIds, editHostGroupIds)) { + setEditOpen(false); + return; + } + const msg = await editMut.mutateAsync({ + oldName: editTarget.name, + newName: next, + hostGroupIds: editHostGroupIds, + }); if (msg?.success) { const affected = (msg.obj as { affected?: number } | undefined)?.affected ?? 0; - messageApi.success(t('pages.groups.renameSuccess', { count: affected })); - setRenameOpen(false); + if (nameChanged) { + messageApi.success(t('pages.groups.renameSuccess', { count: affected })); + } else { + messageApi.success(t('pages.groups.hostRulesSaved', { name: next })); + } + setEditOpen(false); } } @@ -287,6 +324,21 @@ export default function GroupsPage() { setAddClientsOpen(true); } + function openHostRulesFor(g: GroupSummary) { + setHostRulesGroup(g); + setHostRulesOpen(true); + } + + async function saveHostRules(name: string, hostGroupIds: string[]): Promise { + const msg = await groupHostsMut.mutateAsync({ name, hostGroupIds }); + if (msg?.success) { + messageApi.success(t('pages.groups.hostRulesSaved', { name })); + return true; + } + messageApi.error(msg?.msg || t('somethingWentWrong')); + return false; + } + function openRemoveClientsFor(g: GroupSummary) { if (!g.clientCount) { messageApi.info(t('pages.groups.emptyForAction')); @@ -380,10 +432,16 @@ export default function GroupsPage() { onClick: () => openAddClientsFor(row), }, { - key: 'rename', + key: 'hostRules', + icon: , + label: t('pages.groups.hostRules'), + onClick: () => openHostRulesFor(row), + }, + { + key: 'edit', icon: , - label: t('pages.groups.rename'), - onClick: () => openRename(row), + label: t('pages.groups.editGroup'), + onClick: () => openEdit(row), }, { type: 'divider' }, { @@ -416,7 +474,7 @@ export default function GroupsPage() { { title: t('pages.clients.actions'), key: 'actions', - width: 90, + width: 130, render: (_v, row) => ( @@ -428,14 +486,24 @@ export default function GroupsPage() { icon={} /> - + + ), + }, { title: t('pages.groups.upload'), dataIndex: 'up', @@ -623,33 +708,48 @@ export default function GroupsPage() { autoFocus /> + + + setRenameOpen(false)} - onOk={confirmRename} + confirmLoading={editMut.isPending} + onCancel={() => setEditOpen(false)} + onOk={confirmEdit} destroyOnHidden >
- + setRenameValue(e.target.value)} - onPressEnter={confirmRename} + id={`${uid}-edit-name`} + value={editName} + onChange={(e) => setEditName(e.target.value)} + onPressEnter={confirmEdit} placeholder={t('pages.clients.groupPlaceholder')} autoFocus /> + + +
+ + + + void; + ariaLabel?: string; +} + +// Shared host-rule picker for the group create, edit, and quick-assign dialogs. +export default function HostGroupSelect({ value, onChange, ariaLabel }: HostGroupSelectProps) { + const { t } = useTranslation(); + const { hosts, loading } = useHostsQuery(); + // /hosts/list returns one grouped entry per groupId, so option values are unique. + const options = hosts.map((host) => ({ + value: host.groupId, + label: host.remark || host.groupId, + })); + + return ( +