[PR #7064] feat(groups): assign host rules from client groups #6629

Open
opened 2026-11-07 14:34:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • e8c2bc5 feat(db): add client-group host bindings
  • ebe8eeb feat(sub): resolve host tiers by client group
  • 2876d2a feat(api): bind host groups to client groups
  • e75f2f1 feat(ui): choose client groups for host groups
  • 0703623 fix(sub): fold case-duplicate client-group bindings
  • 384233d fix(hosts): serialize unbound client groups as an empty array
  • 3a1185a feat(groups): assign host rules from client groups
  • 9467c08 docs(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_groups join table so previously saved assignments keep working.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Automated checks (all passing):

go build ./...
go test ./internal/web/service ./internal/web/controller ./internal/database ./internal/sub

cd frontend
npm run typecheck
npm run lint
npm run format:check
npm run build

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/list returns one grouped entry per groupId via GetHosts()/groupHosts().

Reviewer reproduction steps:

  1. Groups → Add Group, enter a name and select two host rules → Create. Confirm both appear in the new Host rules column.
  2. Click the host-rules icon or column for a group, change the selection, and save.
  3. Use Edit group to change the name and host rules together; confirm both are applied.
  4. Assign a client to the group and fetch its subscription; confirm the group's host rules are used instead of the default pool.
  5. Clear all host rules and confirm the client falls back to the default host pool.
  6. Disable every host rule bound to a group for one inbound and confirm that inbound contributes no links for the group's clients (fail closed).

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_groups is created automatically by AutoMigrate and pruned on startup when host rules or client groups are removed; no manual migration is required.
  • hostGroupIds is optional on POST /groups/create and POST /groups/rename. Omitting it on rename preserves existing bindings. The new POST /groups/:name/hosts endpoint is additive.
  • Existing host-form bindings are preserved and now surfaced/managed from the Groups page.

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

  • I tested the change locally and confirmed the described behavior (automated Go tests and frontend build; no live browser test).
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7064 **Author:** [@NethminaYasas](https://github.com/NethminaYasas) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/hosts-client-groups` --- ### 📝 Commits (8) - [`e8c2bc5`](https://github.com/MHSanaei/3x-ui/commit/e8c2bc540880be68379f664308900a4c70720a34) feat(db): add client-group host bindings - [`ebe8eeb`](https://github.com/MHSanaei/3x-ui/commit/ebe8eeb438bcd1b86c828bf6882a0b8a95293c5f) feat(sub): resolve host tiers by client group - [`2876d2a`](https://github.com/MHSanaei/3x-ui/commit/2876d2a5cf2145e4486dec599c9629ad4d560c44) feat(api): bind host groups to client groups - [`e75f2f1`](https://github.com/MHSanaei/3x-ui/commit/e75f2f1e0ffc658fc7e6e6704520be85555c5828) feat(ui): choose client groups for host groups - [`0703623`](https://github.com/MHSanaei/3x-ui/commit/0703623f9126103fd561afaed482fdd9819b6512) fix(sub): fold case-duplicate client-group bindings - [`384233d`](https://github.com/MHSanaei/3x-ui/commit/384233da398ab49b4066de6757776cff01da5524) fix(hosts): serialize unbound client groups as an empty array - [`3a1185a`](https://github.com/MHSanaei/3x-ui/commit/3a1185afae4ca5f16f489e8af49d923515de486c) feat(groups): assign host rules from client groups - [`9467c08`](https://github.com/MHSanaei/3x-ui/commit/9467c08a6979e8101fc41aa07b90d6bfdcaa0fd0) docs(api): regenerate client group reference ### 📊 Changes **41 files changed** (+2051 additions, -265 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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_groups` join table so previously saved assignments keep working. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Automated checks (all passing): ```bash go build ./... go test ./internal/web/service ./internal/web/controller ./internal/database ./internal/sub cd frontend npm run typecheck npm run lint npm run format:check npm run build ``` 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/list` returns one grouped entry per `groupId` via `GetHosts()`/`groupHosts()`. Reviewer reproduction steps: 1. Groups → **Add Group**, enter a name and select two host rules → **Create**. Confirm both appear in the new **Host rules** column. 2. Click the host-rules icon or column for a group, change the selection, and save. 3. Use **Edit group** to change the name and host rules together; confirm both are applied. 4. Assign a client to the group and fetch its subscription; confirm the group's host rules are used instead of the default pool. 5. Clear all host rules and confirm the client falls back to the default host pool. 6. Disable every host rule bound to a group for one inbound and confirm that inbound contributes no links for the group's clients (fail closed). Note: verification was via the automated Go/frontend checks above; a live browser smoke test was not run in this session. ## Screenshots / recordings <!-- TODO before publishing: attach screenshots of 1. Add Group dialog with the Host rules selector 2. Edit group dialog 3. Groups table showing the Host rules column and quick action --> ## Breaking changes None for existing configs, API payloads, or deployments: - `host_group_client_groups` is created automatically by `AutoMigrate` and pruned on startup when host rules or client groups are removed; no manual migration is required. - `hostGroupIds` is optional on `POST /groups/create` and `POST /groups/rename`. Omitting it on rename preserves existing bindings. The new `POST /groups/:name/hosts` endpoint is additive. - Existing host-form bindings are preserved and now surfaced/managed from the Groups page. 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 - [x] I tested the change locally and confirmed the described behavior (automated Go tests and frontend build; no live browser test). - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6629
No description provided.