mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #7064] feat(groups): assign host rules from client groups #6629
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6629
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/7064
Author: @NethminaYasas
Created: 11/4/2026
Status: 🔄 Open
Base:
main← Head:feat/hosts-client-groups📝 Commits (8)
e8c2bc5feat(db): add client-group host bindingsebe8eebfeat(sub): resolve host tiers by client group2876d2afeat(api): bind host groups to client groupse75f2f1feat(ui): choose client groups for host groups0703623fix(sub): fold case-duplicate client-group bindings384233dfix(hosts): serialize unbound client groups as an empty array3a1185afeat(groups): assign host rules from client groups9467c08docs(api): regenerate client group reference📊 Changes
41 files changed (+2051 additions, -265 deletions)
View changed files
📝
docs/content/docs/en/reference/api/clients.mdx(+45 -28)📝
docs/public/openapi.json(+83 -7)📝
frontend/public/openapi.json(+83 -7)📝
frontend/src/pages/api-docs/endpoints.ts(+15 -6)➕
frontend/src/pages/groups/GroupHostRulesModal.tsx(+63 -0)📝
frontend/src/pages/groups/GroupsPage.tsx(+141 -41)➕
frontend/src/pages/groups/HostGroupSelect.tsx(+38 -0)📝
frontend/src/schemas/client.ts(+5 -0)➕
internal/database/client_groups.go(+85 -0)➕
internal/database/client_groups_test.go(+123 -0)📝
internal/database/db.go(+8 -0)📝
internal/database/migrate_data.go(+1 -0)📝
internal/database/model/model.go(+9 -0)📝
internal/sub/clash_service.go(+2 -2)➕
internal/sub/host_group_test.go(+395 -0)📝
internal/sub/host_order.go(+5 -1)➕
internal/sub/host_scope.go(+178 -0)📝
internal/sub/host_sub.go(+1 -10)📝
internal/sub/json_service.go(+2 -2)📝
internal/sub/links.go(+1 -1)...and 21 more files
📄 Description
Summary
Client groups now own host-rule assignments. Host rules can be selected while creating a group, edited from the group's edit action, or changed via a quick-assign action on the Groups page. Subscription generation now resolves a client's hosts in this order: per-client binding → host rules bound to the client's group → the existing default host pool.
Why
Host rules previously listed the client groups they applied to. That inverted the relationship: changing which endpoints a group received meant editing every host rule individually, and the Groups page could not show or manage the assignment.
Moving the binding to the client group makes the group the single management point, while reusing the existing
host_group_client_groupsjoin table so previously saved assignments keep working.Type of change
Areas affected
How was this tested?
Automated checks (all passing):
New coverage:
internal/database/client_groups_test.go— schema backfill, startup pruning, Postgres path.internal/sub/host_group_test.go— group tier selection, per-client precedence, fail-closed behavior, hosts-first ordering, format parity, case-duplicate bindings.internal/web/service/client_group_host_binding_test.go— host-rule bindings on create/update, atomic rollback for unknown host groups, rename/delete behavior.A branch-wide CodeRabbit review was also run. It reported one minor finding about duplicate host-rule options; this was verified as a false positive because
/panel/api/hosts/listreturns one grouped entry pergroupIdviaGetHosts()/groupHosts().Reviewer reproduction steps:
Note: verification was via the automated Go/frontend checks above; a live browser smoke test was not run in this session.
Screenshots / recordings
Breaking changes
None for existing configs, API payloads, or deployments:
host_group_client_groupsis created automatically byAutoMigrateand pruned on startup when host rules or client groups are removed; no manual migration is required.hostGroupIdsis optional onPOST /groups/createandPOST /groups/rename. Omitting it on rename preserves existing bindings. The newPOST /groups/:name/hostsendpoint is additive.One intentional behavior change: when a client's group is bound to host rules and every bound host for an inbound is disabled or excluded from the requested format, that inbound fails closed (no links) instead of falling back to the default pool. This prevents a restricted tier from silently receiving unrestricted endpoints.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.