Repository navigation
Go CLI: add list user commands framework - #16201
Conversation
Signed-off-by: Jin Hai <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSix 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 ChangesAdmin List-User Resource Endpoints
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/admin/enterprise_service.go (1)
225-349: ⚡ Quick winConsider 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
📒 Files selected for processing (9)
internal/admin/enterprise_handler.gointernal/admin/enterprise_service.gointernal/admin/handler.gointernal/admin/router.gointernal/cli/admin_command.gointernal/cli/admin_parser.gointernal/cli/cli_http.gointernal/cli/lexer.gointernal/cli/types.go
💤 Files with no reviewable changes (1)
- internal/admin/handler.go
Signed-off-by: Jin Hai <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?