Repository navigation
feat(admin): add user search, status filtering, sorting, and CLI pagination - #21729
Conversation
Apply shared filters before counting and pagination, validate stable sorting, and preserve caller conditions for enterprise extensions.
Support LIST USERS WITH query options and retain pagination totals in CLI output. Keep current report requests as the default and allow enterprise sources to provide their own report executor.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
DAO list query internal/dao/user.go, internal/dao/user_list_test.go |
The DAO uses list options for keyword and active-state filters, ordering, and pagination. It counts filtered rows before pagination and adds an ID tie-breaker. Tests cover filters, totals, ordering, pagination, and query bindings. |
Admin service and API internal/admin/user_list.go, internal/admin/handler.go, internal/admin/service.go, internal/admin/user_detail_test.go, internal/admin/user_list_test.go |
The service parses list parameters and maps DAO results. The handler validates pagination and returns a bad-request response for invalid list queries. Tests cover query options, shared-client filters, and totals. |
CLI parsing and execution internal/cli/admin_user_list.go, internal/cli/admin_parser.go, internal/cli/admin_command.go, internal/cli/admin_user_list_test.go, internal/cli/cli.go |
The CLI parses and validates filters and pagination, sends authenticated GET requests, and formats results with totals. Tests cover requests, parsing errors, response errors, and output formats. The help text documents the command options. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant CLI
participant AdminHandler
participant AdminService
participant UserDAO
CLI->>AdminHandler: GET /admin/users with query parameters
AdminHandler->>AdminService: ListUsers with validated query parameters
AdminService->>UserDAO: List with filters and pagination
UserDAO-->>AdminService: Users and filtered total
AdminService-->>AdminHandler: Mapped users and total
AdminHandler-->>CLI: User-list response
Possibly related PRs
- infiniflow/ragflow#21540: Both changes modify the admin user-list response contract and total-count handling.
- infiniflow/ragflow#21723: Both changes modify pagination behavior for
GET /api/v1/admin/users. - infiniflow/ragflow#21614: Its build-specific admin service implementation connects to the shared handler changed here.
Suggested labels: enhancement, testing, go
Suggested reviewers: buua436, jinhai-cn, wangq8
Merge Risk: 
Minimal · up to 5f3c6
-
No supported merge-blocking issue was identified in the user-listing changes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description clearly explains the API and CLI changes, filtering behavior, pagination, sorting, and accurate totals. It omits the required “### Summary” heading, but the required summary content is present.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 23 functions across 11 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 checks the list at dawn
With filters set and pages drawn
The rows sort neatly, totals show
Through query paths the users flow
A carrot waits when tests all pass
Comment @coderabbitai help to get the list of available commands.
Lynn-Inf
left a comment
There was a problem hiding this comment.
status <> '0' also drops rows where status IS NULL
dao/user.go:184 uses clause.Neq, which renders "user"."status" <> '0'. In SQL that evaluates to NULL for rows whose status is NULL, so those users disappear from both the page and the total. entity.User.Status has default:1, so rows inserted through GORM get '1', but a row that predates the column (or was written before the default existed) stays NULL — and the previous query showed such rows.
If the intent is "not deleted", status IS NULL OR status <> '0' would keep them.
Remove the implicit user.status filter while retaining keyword, activation, ordering, and pagination behavior. Cover zero, default, and NULL statuses in DAO and admin tests and correct misleading query comments.
|
OSS uses is_active for activation and deletes user rows directly. There is no explicit rule that user.status=0 means deleted, so I removed the filter and added tests. |
|
Discussion Nice hardening work. The order-field whitelist, the offset overflow guard, and the top/page exclusivity checks are all worth having, and the tests cover the edge cases well. One compatibility question. validateAdminUserListPagination rejects page_size < 1 unconditionally, including when the caller never sent page_size. The admin UI calls GET /admin/users with no query parameters (web/src/services/admin-service.ts sends an empty params object) and pages the table client-side, and #21723 changes the omitted page_size default to 0. If I am reading both diffs correctly, the outcome depends on merge order: if this PR lands on top of #21723, does that same param-less call start returning 400? If so, could the validation apply only when page_size is explicitly present, or treat 0 as unpaged, so the two PRs stay compatible in either order? Two questions on the CLI side: the doc comment drops the LIST USERS QUOTA OVER and QUOTA TOP forms and flips ACTIVE 30 DAYS to ACTIVE DAYS 30. Does the parser still accept the old forms? If not, that is a breaking change for existing scripts and probably worth a line in the PR description. Reviewed from the diff and the frontend caller only; I did not run the code. |
Extend GET /api/v1/admin/users with email or nickname search, account activation filters, and sorting by create_time or last_login_time. Default to descending creation time. Apply filters before counting and pagination to return accurate totals.
HTTP example:
Add combined query options to the CLI and display total counts: