Compare commits

...

1 Commits

Author SHA1 Message Date
Jin Hai
6370fce3f0 Go CLI: add show users plan summary (#16463)
### Summary

```
RAGFlow(admin)> show users plan summary;
+---------+----------------------------------------------------------------+
| field   | value                                                          |
+---------+----------------------------------------------------------------+
| command | show_users_plan_summary                                        |
| error   | 'Show users plan summary' is implemented in enterprise edition |
+---------+----------------------------------------------------------------+
```

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
2026-06-29 22:28:45 +08:00
6 changed files with 76 additions and 0 deletions

View File

@@ -1706,6 +1706,21 @@ func (h *Handler) ListUsersQuota(c *gin.Context) {
success(c, usersQuota, "")
}
// ShowUsersPlanSummary handle show users plan summary
func (h *Handler) ShowUsersPlanSummary(c *gin.Context) {
usersPlanSummary, err := h.service.ShowUsersPlanSummary()
if err != nil {
if errors.Is(err, common.ErrUserNotFound) {
errorResponse(c, "User not found", 404)
return
}
errorResponse(c, err.Error(), 500)
return
}
success(c, usersPlanSummary, "")
}
// ShowUsersQuotaSummary handle show users quota summary
func (h *Handler) ShowUsersQuotaSummary(c *gin.Context) {
usersQuotaSummary, err := h.service.ShowUsersQuotaSummary()

View File

@@ -904,6 +904,17 @@ func (s *Service) ListUsersQuota(pageIndex, pageSize, top int, quotaThreshold *i
return result, nil
}
// ShowUsersPlanSummary show users plan summary for enterprise edition
func (s *Service) ShowUsersPlanSummary() (map[string]interface{}, error) {
result := map[string]interface{}{
"command": "show_users_plan_summary",
"error": "'Show users plan summary' is implemented in enterprise edition",
}
return result, nil
}
// ShowUsersQuotaSummary show users quota summary for enterprise edition
func (s *Service) ShowUsersQuotaSummary() (map[string]interface{}, error) {

View File

@@ -138,6 +138,7 @@ func (r *Router) Setup(engine *gin.Engine) {
protected.GET("/users/documents", r.handler.ListUsersDocuments)
protected.GET("/users/index", r.handler.ListUsersIndex)
protected.GET("/users/quota", r.handler.ListUsersQuota)
protected.GET("/users/plan/summary", r.handler.ShowUsersPlanSummary)
protected.GET("/users/quota/summary", r.handler.ShowUsersQuotaSummary)
protected.GET("/ingestion/tasks/summary", r.handler.ShowIngestionTasksSummary)
protected.GET("/data/summary", r.handler.ShowDataSummary)

View File

@@ -2283,6 +2283,36 @@ func (c *CLI) AdminShowUsersActivityCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
func (c *CLI) AdminShowUsersPlanCommand(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
apiURL := "/admin/users/plan/summary"
resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get users activity: %w", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("failed to get users plan: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
}
var result CommonDataResponse
if err = json.Unmarshal(resp.Body, &result); err != nil {
return nil, fmt.Errorf("get users plan failed: invalid JSON (%w)", err)
}
if result.Code != 0 {
return nil, fmt.Errorf("%s", result.Message)
}
result.Duration = resp.Duration
return &result, nil
}
// ListUsers lists all users (admin mode only)
// Returns (result_map, error) - result_map is non-nil for benchmark mode
func (c *CLI) AdminListUsersCommand(cmd *Command) (ResponseIf, error) {

View File

@@ -2525,6 +2525,8 @@ func (p *Parser) parseAdminShowUsersCommands() (*Command, error) {
return cmd, nil
case TokenActivity:
return p.parseAdminShowUsersActivity()
case TokenPlan:
return p.parseAdminShowUsersPlan()
default:
return nil, fmt.Errorf("invalid command")
}
@@ -2581,6 +2583,21 @@ commandLoop:
return cmd, nil
}
func (p *Parser) parseAdminShowUsersPlan() (*Command, error) {
p.nextToken() // consume PLAN
if p.curToken.Type != TokenSummary {
return nil, fmt.Errorf("expected SUMMARY")
}
p.nextToken()
cmd := NewCommand("admin_show_users_plan_command")
if p.curToken.Type == TokenSemicolon {
p.nextToken()
}
return cmd, nil
}
// LIST USERS;
// LIST USERS ACTIVE 30 DAYS; // default 7 days
// LIST USERS INACTIVE 30 DAYS; // default 7 days

View File

@@ -191,6 +191,8 @@ func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
return c.AdminShowUsersSummaryCommand(cmd)
case "admin_show_users_activity_command":
return c.AdminShowUsersActivityCommand(cmd)
case "admin_show_users_plan_command":
return c.AdminShowUsersPlanCommand(cmd)
case "admin_list_users_command":
return c.AdminListUsersCommand(cmd)
case "admin_list_users_condition_command":