Repository navigation
feat(users): display and sort registered HWID counts - #951
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe user list now returns registered HWID counts. The dashboard displays those counts, supports sorting by count, and refreshes the users query after HWID changes. ChangesUser HWID Counts
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant DashboardUsersTable
participant UserOperation
participant get_users
participant UserHWID
DashboardUsersTable->>UserOperation: Request user list
UserOperation->>get_users: Load users with HWID counts
get_users->>UserHWID: Count rows for each user
UserHWID-->>get_users: Return correlated counts
get_users-->>UserOperation: Return users with counts
UserOperation-->>DashboardUsersTable: Provide user-list response
Suggested reviewers: Merge Risk | ⚪ Minimal · up to
|
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ❓ Inconclusive | Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 8 files. (5 skipped: 4… | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
-
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title check ✅ Passed The title clearly and concisely summarizes the main change: displaying and sorting registered HWID counts in the Users feature. Linked Issues check ✅ Passed The PR meets the coding requirements in [ #516]. The backend loadsUserHWIDcounts for the user-list endpoint and exposeshwid_count. The Users UI displays the count on desktop and mobile. The UI a…Out of Scope Changes check ✅ Passed The changes stay within [ #516]. Backend query support, API types, table rendering, sort controls, cache handling, and localization all support displaying or sorting registered HWID counts in the Users…
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 8 files. (5 skipped: 4 unsupported, 1 too large.)
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit counts each device in the queue,
Fingerprints mark the totals, neat and true.
Sort them low or sort them high,
Fresh counts appear when changes fly.
The users list hops into view.
Comment @coderabbitai help to get the list of available commands.
|
@coderabbitai review |
✅ Action performedReview finished.
|
f0dfa58 to
cfbf25d
Compare
The HWID list needs hwids.read, but the users list needs only users.read, so the new count column exposed device counts to roles that cannot see devices. Without hwids.read the count is not loaded and a hwid_count sort is ignored, the same way node filters are ignored without nodes.stats. hwid_count is now null when it was not loaded instead of a misleading 0, so a caller that skips the count cannot fail validation.
Counts per user, ascending and descending sort with an unchanged total, and an admin without hwids.read who gets no counts and no device sort while an admin with it gets both. The shared set_user_hwids helper clears a user's devices first, since SQLite keeps a deleted user's devices and can reuse its id.
….read Hide the device count column, its mobile line and the sort option for admins without hwids.read, matching the backend. Regenerate the API client with the pinned orval: hwid_count is now nullable, and UserListItem uses the same inline field types as the rest of the client.
SQLite keeps a deleted user's devices (foreign keys off) and can give its id to the next test's user, so the two device count tests from #951 left devices that a later test inherited: running them before tests/api/test_hwid.py made test_hwid_respects_admin_role_policy see 3 devices instead of 1. Clear the devices before deleting the users.
…ain bba95f274 Checked with git ls-remote on 2026-10-11 02:55 UTC. Panel dev moved from d94e157 to 83fe90e with 22 commits; main is still v5.4.1. - PasarGuard#879 (2d0ca81, loopback Xray client inbounds) is ported by design: the fork took the open pull request on 2026-09-25 as 2e7fc45 with migration bfd88026565b, the same listener rewrite. - PasarGuard#934 (a5b28f3) moves from the port queue to a dated waiver until 2026-11-09: the fork refuses to delete a core that nodes still use (W3-013, fix/node-health) instead of restarting those nodes. - PasarGuard#993 (Hysteria2 FinalMask without a udp mask) is queued until 2026-10-18: the fork has the same FinalMask | dict field and the same non-null-safe udpHop reads, so a udpHop-only host can fail the whole subscription. - PasarGuard#984, PasarGuard#985, PasarGuard#986, PasarGuard#989, PasarGuard#944, PasarGuard#864, PasarGuard#948, PasarGuard#951, PasarGuard#778, PasarGuard#774, PasarGuard#787, PasarGuard#994, PasarGuard#865, PasarGuard#875, PasarGuard#718, PasarGuard#967, PasarGuard#772, PasarGuard#662, PasarGuard#995 and PasarGuard#913 are queued as security: no until 2026-10-25, each with its reason; PasarGuard#913's node-removal half is already in the fork through sync_remove_users. - The branch commits that upstream squash-merged (the three dashboard branches, telegram/tests, fix/core-editor-api-section-followup, fix/hwid-count-test-cleanup, fix/hysteria-finalmask-quic-only) follow their squash, by patch-id or by an equal tree. Scripts main moved to bba95f274 (PasarGuard#35, PasarGuard#36, PasarGuard#37 after PasarGuard#34). The three squashes are queued security: no until 2026-10-25, and their pre-squash branch commits are waived as superseded (equal trees). Against live upstream the panel gate now fails only on the 17 port-queue commits classified security: yes, and the forks gate only on node f72ac0ef (security: yes). No upstream commit is undecided.
* feat(users): display and sort registered HWID counts * fix(users): show device counts only to admins with hwids.read The HWID list needs hwids.read, but the users list needs only users.read, so the new count column exposed device counts to roles that cannot see devices. Without hwids.read the count is not loaded and a hwid_count sort is ignored, the same way node filters are ignored without nodes.stats. hwid_count is now null when it was not loaded instead of a misleading 0, so a caller that skips the count cannot fail validation. * test(users): cover device counts in the users list Counts per user, ascending and descending sort with an unchanged total, and an admin without hwids.read who gets no counts and no device sort while an admin with it gets both. The shared set_user_hwids helper clears a user's devices first, since SQLite keeps a deleted user's devices and can reuse its id. * fix(dashboard): show the device count column and sort only with hwids.read Hide the device count column, its mobile line and the sort option for admins without hwids.read, matching the backend. Regenerate the API client with the pinned orval: hwid_count is now nullable, and UserListItem uses the same inline field types as the rest of the client. --------- Co-authored-by: T3ST3ST3R0N <[email protected]> (cherry picked from commit cc7c710) Fork port: backend and tests only. The dashboard half is owed by lane B-DASH. Conflicts resolved against fork main 2da54c4: get_users keeps the fork populate_existing option, list_users keeps the fork group restriction before the hwids.read gate, and get_admin_users_for_node_sync from upstream context is not added. tests/api/test_permission_leaks.py is not in the fork; its device count test is ported into tests/api/test_user_list_hwid_count_scope.py. (cherry picked from commit cdab821ab9382d2a461c656924d0bab2157855bc)
SQLite keeps a deleted user's devices (foreign keys off) and can give its id to the next test's user, so the two device count tests from PasarGuard#951 left devices that a later test inherited: running them before tests/api/test_hwid.py made test_hwid_respects_admin_role_policy see 3 devices instead of 1. Clear the devices before deleting the users. (cherry picked from commit 3ef603b) Fork port: tests/api/test_permission_leaks.py is not in the fork; the same clean-up is in tests/api/test_user_list_hwid_count_scope.py. (cherry picked from commit 8aa3b56483275da41b5d4e749b8be06d4f829c94)
… users Ports the device count test of upstream tests/api/test_permission_leaks.py (PasarGuard#951, with the PasarGuard#994 clean-up), which the fork does not have, and adds an own-scope admin with hwids.read that sorts by hwid_count both ways over a search that also matches three other admins' users with more devices: the total stays 1 and only its own user and count are returned. (cherry picked from commit c2f34e699400c06bdb179769acaf2bfd596e16c6)
The fork scopes hwids.read: GET /api/user/{id}/hwids answers 404 for another admin's user when hwids.read is OWN. Upstream PasarGuard#951 gates the users list count and sort on hwids.read without its scope, so a role with users.read ALL and hwids.read OWN got every user's device count and could sort all users by it. The count and the hwid_count sort now load only when hwids.read is ALL or the listing is already limited to the admin's own users.
(cherry picked from commit 548ecaa9ccbedbbaa5cf5fe1f87b79568b1ab001)
…ef603b as carried, with the leak tests replaced Both rows stay in the port queue until the dashboard half of PasarGuard#951 lands on port/b-dash-951 (then 2f76096). Upstream's test_permission_leaks.py hunks are replaced by tests/api/test_user_list_hwid_count_scope.py, which checks the same hwids.read gate plus the own-scope cases and the grant/revoke race, rather than dropped. (cherry picked from commit 1c50b4d96d1d0a555ef36c5f986679a727a90bbe)
* feat(cleanup): delete inactive users by last activity * fix(cleanup): remove deleted active and on_hold users from the nodes The inactive target matches users of any status, but the cleanup delete only removed database rows. Active users deleted this way kept working on the nodes until the next full resync, and their released WireGuard IPs could be handed out while the old peers were still configured. The existing on_hold target had the same gap. The cleanup delete now returns the deleted users that nodes still serve (active and on_hold), and the operation dispatches their removal like the bulk delete does. Dry runs dispatch nothing. Tests: inactive selection by online_at with the created_at fallback, the required cutoff, and node removal for active and on_hold users only. --------- Co-authored-by: T3ST3ST3R0N <[email protected]> (cherry picked from commit 83fe90e) Fork resolution, backend half only: - app/db/crud/user.py: the inactive branch of _cleanup_target_user_conditions is upstream's, with the fork's to_utc_for_filter on both bounds like every other branch, and the fork's allowed_group_ids filter is kept. - app/operation/user.py and app/db/crud/user.py keep the fork's chunked delete: remove_expired_users still returns only the usernames and still calls on_chunk_deleted=sync_remove_users for every deleted chunk, instead of upstream's (usernames, node_users) return and the single sync_remove_users afterwards. Upstream's node-sync filter (only active and on_hold deleted users reach the nodes) is therefore not ported: the fork removes every deleted chunk, which is a no-op for a user already off the nodes. tests/api/test_user_cleanup.py asserts the fork's set instead of upstream's three memberships. - The dashboard half (the four locale files, dashboard/src/pages/_dashboard.settings.cleanup.tsx and the generated dashboard/src/service/api/index.ts) is left to the dashboard lane, as the PasarGuard#951 row already does.
Summary
Show each user's registered HWID count in the Users table, including zero for users without registered devices. Desktop gets a sortable HWIDs column; mobile shows the count below the username. Both layouts can sort by HWID count from the sort menu.
Closes #516.
hwid_countto user-list responses and supportsort=hwid_count/sort=-hwid_count, with a user-ID tie-breaker for stable pagination.Type of change
Checklist
Testing
tests/api/test_hwid.pyandtests/api/test_user.py: 91 passed, 1 failed. The sametest_bulk_apply_template_to_usersfailure reproduces on unchangeddevat26047f6b.Screenshots
Captured from the running production build with a local database containing synthetic users/devices.
Desktop — highest HWID count first
Sort menu
Mobile
Persian RTL — dark mode
Notes for reviewers
Counts represent registered hardware IDs, not currently online devices. Existing user visibility/ownership filters are applied before pagination. The new count is loaded only for the full user-list endpoint.
Summary by CodeRabbit