Skip to content

Go: add show users plan quota - #16818

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix536
Jul 10, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix536

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

RAGFlow(admin)> show users plan quota 100;
+---------+------------------------------------------+
| field   | value                                    |
+---------+------------------------------------------+
| quota   | 100                                      |
| command | show_users_plan_quota                    |
| error   | 'Show users plan quota' is not supported |
+---------+------------------------------------------+

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The admin CLI now separates users plan summary and quota commands. Quota values are parsed and range-validated, dispatched to a dedicated handler, and served through a protected admin endpoint backed by a new enterprise service method.

Changes

Users plan quota flow

Layer / File(s) Summary
CLI syntax and dispatch
internal/cli/admin_parser.go, internal/cli/admin_command.go, internal/cli/cli_http.go
SHOW USERS PLAN SUMMARY and SHOW USERS PLAN QUOTA <number> emit separate commands, validate quota values from 0 through 100, and invoke dedicated CLI handlers.
Admin quota endpoint
internal/admin/router.go, internal/admin/enterprise_handler.go, internal/admin/enterprise_service.go
A protected users plan route parses the optional quota parameter, maps errors, and returns service-generated quota command data.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AdminCLI
  participant AdminRouter
  participant ShowUsersPlan
  participant EnterpriseService
  AdminCLI->>AdminRouter: GET /admin/users/plan?quota=quota
  AdminRouter->>ShowUsersPlan: route request
  ShowUsersPlan->>EnterpriseService: ShowUsersPlanQuota(quota)
  EnterpriseService-->>ShowUsersPlan: quota command data
  ShowUsersPlan-->>AdminCLI: response data or error
Loading

Possibly related PRs

Suggested labels: 💞 feature

Poem

A bunny parses PLAN beneath the moon,
SUMMARY hops, QUOTA follows soon.
Numbers stay within their bounds,
Admin routes return their sounds.
Two commands now dance in tune.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks the required brief summary and background, and only shows an example output. Add a short Summary explaining what the PR changes and why, plus any relevant background or scope notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding support for the users plan quota command.
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.

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.

@JinHai-CN
JinHai-CN marked this pull request as ready for review July 10, 2026 11:10
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 10, 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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/cli/admin_command.go (1)

1691-1691: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Copy-paste error in failure message.

The error message says "failed to get users activity" but this handler fetches the users plan summary. This is a copy-paste artifact from AdminShowUsersActivityCommand.

🔧 Proposed fix
-		return nil, fmt.Errorf("failed to get users activity: %w", err)
+		return nil, fmt.Errorf("failed to get users plan summary: %w", err)
🤖 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/cli/admin_command.go` at line 1691, In the users plan summary
handler, update the error returned at the existing fmt.Errorf call to say
“failed to get users plan summary” instead of “failed to get users activity,”
matching the handler’s operation and distinguishing it from
AdminShowUsersActivityCommand.
🤖 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/admin/enterprise_handler.go`:
- Around line 1566-1590: ShowUsersPlan parses quota but does not enforce the
valid 0–100 range. After converting quotaStr in ShowUsersPlan, reject values
below 0 or above 100 with CodeBadRequest and the same quota validation message
used by the CLI, before calling ShowUsersPlanQuota.

In `@internal/cli/admin_parser.go`:
- Around line 2617-2618: Update the validation after consuming the QUOTA token
in the parser to return an error stating that a number is expected instead of
“expected QUOTA”; locate the relevant token parsing logic in the admin parser
and change only this misleading message.

---

Outside diff comments:
In `@internal/cli/admin_command.go`:
- Line 1691: In the users plan summary handler, update the error returned at the
existing fmt.Errorf call to say “failed to get users plan summary” instead of
“failed to get users activity,” matching the handler’s operation and
distinguishing it from AdminShowUsersActivityCommand.
🪄 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: 0e7e183c-3edd-4fe6-8f6e-875d69cf75e2

📥 Commits

Reviewing files that changed from the base of the PR and between e53235e and f83ba6a.

📒 Files selected for processing (6)
  • internal/admin/enterprise_handler.go
  • internal/admin/enterprise_service.go
  • internal/admin/router.go
  • internal/cli/admin_command.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go

Comment on lines +1566 to +1590
// ShowUsersPlan handle show users plan
func (h *Handler) ShowUsersPlan(c *gin.Context) {
var quota int
quotaStr := c.Query("quota")
if quotaStr != "" {
var err error
quota, err = strconv.Atoi(quotaStr)
if err != nil {
common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be an integer")
return
}
}
usersPlanQuota, err := h.service.ShowUsersPlanQuota(quota)
if err != nil {
if errors.Is(err, common.ErrUserNotFound) {
common.ErrorWithCode(c, common.CodeNotFound, "User not found")
return
}
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}

common.SuccessWithData(c, usersPlanQuota, "")
}

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Missing server-side quota range validation.

The CLI parser validates quota is within 0–100, but the API handler accepts any integer from the query string. A direct API caller could bypass the CLI and send arbitrary quota values. Consider adding range validation server-side to keep the contract consistent.

🛡️ Proposed fix
 	quotaStr := c.Query("quota")
 	if quotaStr != "" {
 		var err error
 		quota, err = strconv.Atoi(quotaStr)
 		if err != nil {
 			common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be an integer")
 			return
 		}
+		if quota < 0 || quota > 100 {
+			common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be between 0 and 100")
+			return
+		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// ShowUsersPlan handle show users plan
func (h *Handler) ShowUsersPlan(c *gin.Context) {
var quota int
quotaStr := c.Query("quota")
if quotaStr != "" {
var err error
quota, err = strconv.Atoi(quotaStr)
if err != nil {
common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be an integer")
return
}
}
usersPlanQuota, err := h.service.ShowUsersPlanQuota(quota)
if err != nil {
if errors.Is(err, common.ErrUserNotFound) {
common.ErrorWithCode(c, common.CodeNotFound, "User not found")
return
}
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}
common.SuccessWithData(c, usersPlanQuota, "")
}
// ShowUsersPlan handle show users plan
func (h *Handler) ShowUsersPlan(c *gin.Context) {
var quota int
quotaStr := c.Query("quota")
if quotaStr != "" {
var err error
quota, err = strconv.Atoi(quotaStr)
if err != nil {
common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be an integer")
return
}
if quota < 0 || quota > 100 {
common.ErrorWithCode(c, common.CodeBadRequest, "Quota must be between 0 and 100")
return
}
}
usersPlanQuota, err := h.service.ShowUsersPlanQuota(quota)
if err != nil {
if errors.Is(err, common.ErrUserNotFound) {
common.ErrorWithCode(c, common.CodeNotFound, "User not found")
return
}
common.ErrorWithCode(c, common.CodeServerError, err.Error())
return
}
common.SuccessWithData(c, usersPlanQuota, "")
}
🤖 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_handler.go` around lines 1566 - 1590, ShowUsersPlan
parses quota but does not enforce the valid 0–100 range. After converting
quotaStr in ShowUsersPlan, reject values below 0 or above 100 with
CodeBadRequest and the same quota validation message used by the CLI, before
calling ShowUsersPlanQuota.

Comment on lines +2617 to +2618
if p.curToken.Type != TokenNumber {
return nil, fmt.Errorf("expected QUOTA")

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Misleading error message after QUOTA token.

After consuming the QUOTA token, the parser expects a number. The error message "expected QUOTA" is confusing since QUOTA was already consumed. It should indicate a number was expected.

🔧 Proposed fix
 		if p.curToken.Type != TokenNumber {
-			return nil, fmt.Errorf("expected QUOTA")
+			return nil, fmt.Errorf("expected number after QUOTA")
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if p.curToken.Type != TokenNumber {
return nil, fmt.Errorf("expected QUOTA")
if p.curToken.Type != TokenNumber {
return nil, fmt.Errorf("expected number after QUOTA")
🤖 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/cli/admin_parser.go` around lines 2617 - 2618, Update the validation
after consuming the QUOTA token in the parser to return an error stating that a
number is expected instead of “expected QUOTA”; locate the relevant token
parsing logic in the admin parser and change only this misleading message.

@JinHai-CN
JinHai-CN merged commit 106c2d0 into infiniflow:main Jul 10, 2026
4 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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant