Skip to content

Go CLI: add list user commands framework - #16201

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix472
Jun 19, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix472

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(admin)> list user '[email protected]' datasets;
+--------------------+-------------+-----------------------------------------------------------+----------+
| command            | email       | error                                                     | nickname |
+--------------------+-------------+-----------------------------------------------------------+----------+
| list_user_datasets | [email protected] | 'list user datasets' is implemented in enterprise edition | aaa      |
+--------------------+-------------+-----------------------------------------------------------+----------+
RAGFlow(admin)> list user '[email protected]' agents;
+------------------+-------------+---------------------------------------------------------+----------+
| command          | email       | error                                                   | nickname |
+------------------+-------------+---------------------------------------------------------+----------+
| list_user_agents | [email protected] | 'list user agents' is implemented in enterprise edition | aaa      |
+------------------+-------------+---------------------------------------------------------+----------+
RAGFlow(admin)> list user '[email protected]' searches;
+--------------------+-------------+-----------------------------------------------------------+----------+
| command            | email       | error                                                     | nickname |
+--------------------+-------------+-----------------------------------------------------------+----------+
| list_user_searches | [email protected] | 'list user searches' is implemented in enterprise edition | aaa      |
+--------------------+-------------+-----------------------------------------------------------+----------+
RAGFlow(admin)> list user '[email protected]' chats;
+-----------------+-------------+--------------------------------------------------------+----------+
| command         | email       | error                                                  | nickname |
+-----------------+-------------+--------------------------------------------------------+----------+
| list_user_chats | [email protected] | 'list user chats' is implemented in enterprise edition | aaa      |
+-----------------+-------------+--------------------------------------------------------+----------+
RAGFlow(admin)> list user '[email protected]' files;
+--------------------+-------------+-----------------------------------------------------------+----------+
| command            | email       | error                                                     | nickname |
+--------------------+-------------+-----------------------------------------------------------+----------+
| list_user_datasets | [email protected] | 'list user datasets' is implemented in enterprise edition | aaa      |
+--------------------+-------------+-----------------------------------------------------------+----------+
RAGFlow(admin)> list user '[email protected]' models;
+------------------+-------------+---------------------------------------------------------+----------+
| command          | email       | error                                                   | nickname |
+------------------+-------------+---------------------------------------------------------+----------+
| list_user_models | [email protected] | 'list user models' is implemented in enterprise edition | aaa      |
+------------------+-------------+---------------------------------------------------------+----------+

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 66fdd91f-4a7b-40c4-8a1c-1c2b0c7809ab

📥 Commits

Reviewing files that changed from the base of the PR and between dba388a and 75d00d5.

📒 Files selected for processing (1)
  • internal/cli/admin_command.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/cli/admin_command.go

📝 Walkthrough

Walkthrough

Six new admin endpoints are added to list per-user resources (datasets, agents, chats, searches, models, files). The change spans enterprise service methods, Gin HTTP handlers replacing older GetUserDatasets/GetUserAgents handlers, router registration, and a full CLI pipeline including a new SEARCHES lexer token, parser branches, command implementations, and HTTP dispatch wiring.

Changes

Admin List-User Resource Endpoints

Layer / File(s) Summary
Enterprise service methods
internal/admin/enterprise_service.go
Adds six Service methods (ListUserDatasets through ListUserFiles) that look up a user by email via GORM and return a fixed single-element result slice with resource command name, email, nickname, and an enterprise-edition message.
HTTP handlers and router wiring
internal/admin/enterprise_handler.go, internal/admin/handler.go, internal/admin/router.go
Adds six Handler methods with username validation and 400/500/success responses. Removes old GetUserDatasets/GetUserAgents from handler.go. Rewires router to register all six endpoints under /users/:username/* using the new handler methods.
CLI lexer token and keyword
internal/cli/types.go, internal/cli/lexer.go
Adds TokenSearches constant to the iota block and maps the SEARCHES identifier to it in lookupIdent.
CLI parser extension
internal/cli/admin_parser.go
Extends parseAdminListUserCommand to branch on DATASETS, AGENTS, CHATS, SEARCHES, MODELS, and FILES tokens, emitting dedicated admin_list_user_*_command values for each and updating the default error message.
CLI command implementations and dispatch
internal/cli/admin_command.go, internal/cli/cli_http.go
Adds six AdminListUser*Command methods that validate admin mode/token, call the REST endpoint, unmarshal CommonResponse, and set Duration. Adds matching case branches in ExecuteAdminCommand to wire each command type to its handler.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

💞 feature, size:L

Poem

🐰 Hop hop, the admin can now peek,
At datasets, chats, and files to seek,
Agents, models, searches too—
Six new commands, all shiny and new!
The router hops from endpoint to end,
Around the warren, resources blend. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description only shows example output from the new commands without addressing the required template sections: 'What problem does this PR solve?' and 'Type of change'. Fill in the required template sections to explain the problem being solved and classify the type of change (likely 'New Feature').
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go CLI: add list user commands framework' accurately describes the main change: introducing a framework for new list user commands in the Go CLI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 19, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 19, 2026 03:22
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jun 19, 2026

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/admin/enterprise_service.go (1)

225-349: ⚡ Quick win

Consider extracting the common user lookup and response pattern.

All six methods (ListUserDatasets, ListUserAgents, ListUserChats, ListUserSearches, ListUserModels, ListUserFiles) share identical structure: GORM user lookup by email, error handling, and single-element result construction. The only variance is the command name and error message string.

♻️ Refactor to reduce duplication
+// listUserResource is a helper that looks up a user and returns a standard enterprise-edition response
+func (s *Service) listUserResource(email, commandName, commandDisplay string) ([]map[string]interface{}, error) {
+	var user entity.User
+	err := dao.DB.Where("email = ?", email).First(&user).Error
+	if err != nil {
+		return nil, common.ErrUserNotFound
+	}
+
+	result := []map[string]interface{}{
+		{
+			"command":  commandName,
+			"email":    user.Email,
+			"nickname": user.Nickname,
+			"error":    fmt.Sprintf("'%s' is implemented in enterprise edition", commandDisplay),
+		},
+	}
+	return result, nil
+}
+
 // ListUserDatasets show user datasets for enterprise edition
 func (s *Service) ListUserDatasets(email string) ([]map[string]interface{}, error) {
-	// Query user by email
-	var user entity.User
-	err := dao.DB.Where("email = ?", email).First(&user).Error
-	if err != nil {
-		return nil, common.ErrUserNotFound
-	}
-
-	result := []map[string]interface{}{
-		{
-			"command":  "list_user_datasets",
-			"email":    user.Email,
-			"nickname": user.Nickname,
-			"error":    "'list user datasets' is implemented in enterprise edition",
-		},
-	}
-
-	return result, nil
+	return s.listUserResource(email, "list_user_datasets", "list user datasets")
 }
 
 // ListUserAgents show user agents for enterprise edition
 func (s *Service) ListUserAgents(email string) ([]map[string]interface{}, error) {
-	// Query user by email
-	var user entity.User
-	err := dao.DB.Where("email = ?", email).First(&user).Error
-	if err != nil {
-		return nil, common.ErrUserNotFound
-	}
-
-	result := []map[string]interface{}{
-		{
-			"command":  "list_user_agents",
-			"email":    user.Email,
-			"nickname": user.Nickname,
-			"error":    "'list user agents' is implemented in enterprise edition",
-		},
-	}
-
-	return result, nil
+	return s.listUserResource(email, "list_user_agents", "list user agents")
 }

Apply the same pattern to the remaining four methods.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/admin/enterprise_service.go` around lines 225 - 349, These six
methods (ListUserDatasets, ListUserAgents, ListUserChats, ListUserSearches,
ListUserModels, ListUserFiles) contain duplicate code for user lookup and
response construction. Extract the common pattern into a private helper function
that accepts the email and command name as parameters, performs the GORM user
lookup with the same error handling, and returns the result map with the command
and error fields populated. Then replace the duplicate code in each of the six
methods with a call to this new helper function, passing only the email and the
respective command name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cli/admin_command.go`:
- Around line 2566-2599: The AdminListUserFilesCommand function has a copy-paste
error where the API endpoint and error messages reference "datasets" instead of
"files". Update the apiURL variable to construct the endpoint as
`/admin/users/%s/files` instead of `/admin/users/%s/datasets`, and then update
all error messages throughout the function (in the error returns for network
failures, HTTP status checks, and JSON unmarshaling) to reference "files"
instead of "datasets" to ensure consistency with the function's purpose.

---

Nitpick comments:
In `@internal/admin/enterprise_service.go`:
- Around line 225-349: These six methods (ListUserDatasets, ListUserAgents,
ListUserChats, ListUserSearches, ListUserModels, ListUserFiles) contain
duplicate code for user lookup and response construction. Extract the common
pattern into a private helper function that accepts the email and command name
as parameters, performs the GORM user lookup with the same error handling, and
returns the result map with the command and error fields populated. Then replace
the duplicate code in each of the six methods with a call to this new helper
function, passing only the email and the respective command name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af346ace-0421-4723-b23c-a2e2fe486ac8

📥 Commits

Reviewing files that changed from the base of the PR and between 7214a23 and dba388a.

📒 Files selected for processing (9)
  • internal/admin/enterprise_handler.go
  • internal/admin/enterprise_service.go
  • internal/admin/handler.go
  • internal/admin/router.go
  • internal/cli/admin_command.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/lexer.go
  • internal/cli/types.go
💤 Files with no reviewable changes (1)
  • internal/admin/handler.go

Comment thread internal/cli/admin_command.go Resolved
Signed-off-by: Jin Hai <[email protected]>
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (b409cfc) to head (75d00d5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16201      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 11499f7 into infiniflow:main Jun 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant