Skip to content

feat(admin): add user search, status filtering, sorting, and CLI pagination - #21729

Merged
wangq8 merged 6 commits into
infiniflow:mainfrom
QAQadws:codex/admin-user-list-filters
Nov 2, 2026
Merged

wangq8 merged 6 commits into
infiniflow:mainfrom
QAQadws:codex/admin-user-list-filters

Conversation

@QAQadws

@QAQadws QAQadws commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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:

GET /api/v1/admin/users?keyword=alice&status=active&order=create_time&sort=desc&page=1&page_size=10

Add combined query options to the CLI and display total counts:

LIST USERS WITH keyword 'alice' status 'active' order 'create_time' sort 'desc' page 1 page_size 10;

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.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d3cfdb3-8143-43ca-8193-5d5b0a93f7d7
Commits

Reviewing files that changed from the base of the PR and between 102c508 and 5f3c67b.

Files selected for processing: 5
  • internal/admin/user_detail_test.go
  • internal/admin/user_list.go
  • internal/admin/user_list_test.go
  • internal/dao/user.go
  • internal/dao/user_list_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The admin user-list flow supports filtering, sorting, and pagination through the API and CLI. The DAO applies filters and returns matching totals. The CLI validates options, sends requests, and formats user data and totals.

Changes: Admin user listing

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: Normal

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
Loading

Possibly related PRs

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: admin user search, status filtering, sorting, and CLI pagination.
Description check Passed 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…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

❤️ Share

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.

@QAQadws QAQadws added the ci Continue Integration label Oct 30, 2026
@QAQadws
QAQadws requested a review from Lynn-Inf October 30, 2026 02:13

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@QAQadws

QAQadws commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

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.

@QAQadws
QAQadws requested a review from Lynn-Inf October 30, 2026 07:08
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

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.

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @QAQadws , LGTM.

@wangq8
wangq8 merged commit d554aba into infiniflow:main Nov 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants