Skip to content

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio - #4772

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
Micah-Zheng:fix/admin-group-ratio-display
May 12, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
Micah-Zheng:fix/admin-group-ratio-display

Conversation

@Micah-Zheng

@Micah-Zheng Micah-Zheng commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

问题描述

在 API 密钥列表页,管理员(role >= 10)看到的分组倍率与实际计费不一致。

复现步骤:

  1. 配置 GroupGroupRatio,例如 VIP 用户使用 default 分组的特殊倍率为 1(全局 default 倍率为 2)
  2. 以管理员身份登录(同时属于 VIP 分组)
  3. 创建 API 密钥时选择 default 分组,弹窗显示倍率 1x(正确)
  4. 创建成功后,密钥列表页显示倍率 2x(错误)

根本原因

api-keys-columns.tsx 中的 useGroupRatios hook 对管理员和普通用户走了不同的数据源:

  • 管理员:调用 getSystemOptions,直接读取全局 GroupRatio 配置,不考虑 GroupGroupRatio(用户分组对特定分组的特殊倍率)
  • 普通用户:调用 getUserGroups,后端已经根据当前用户分组计算出实际倍率(考虑了 GroupGroupRatio)

而创建/编辑弹窗始终调用 getUserGroups,所以两处显示不一致。

修复方案

统一使用 getUserGroups 获取倍率,管理员和普通用户走相同路径。getUserGroups 后端已经正确处理了 GroupGroupRatio 逻辑,返回的是当前用户视角下各分组的实际倍率。

影响范围

  • 仅影响前端显示,不影响实际计费逻辑
  • 修复后管理员在密钥列表页看到的倍率与创建弹窗、实际计费一致

测试

  • 配置 GroupGroupRatio 后,管理员密钥列表页倍率显示与创建弹窗一致
  • 普通用户倍率显示不受影响

Signed-off-by: Micah-Zheng [email protected]

Summary by CodeRabbit

  • Refactor
    • Simplified the group ratio data retrieval logic in API key management, reducing code complexity and removing unnecessary role-based conditionals for improved maintainability.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The PR simplifies group ratio fetching in the API keys column component by removing role-based conditional logic. The useGroupRatios() hook no longer branches between admin system-wide ratios and user self-group ratios; it now returns only the user-self-groups query result.

Changes

Group Ratios Simplification

Layer / File(s) Summary
Import Cleanup
web/default/src/features/keys/components/api-keys-columns.tsx
useMemo and useAuthStore imports removed as they are no longer needed for role-based conditional selection.
Hook Refactor
web/default/src/features/keys/components/api-keys-columns.tsx
useGroupRatios() eliminates admin/system-options fetching and the conditional useMemo selection, returning only the getUserGroups query data (or {}).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through tangled thickets,
Snips away the role-check picks-it,
Now one path shines, so clean and neat,
Groups query flows with simpler beat! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: using getUserGroups for ratio display to respect GroupGroupRatio, which directly addresses the core issue of unifying the data source for displaying group ratios across admin and regular user code paths.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@Calcium-Ion
Calcium-Ion merged commit 7fe896d into QuantumNous:main May 12, 2026
1 check passed
xyfacai pushed a commit to xyfacai/new-api that referenced this pull request May 30, 2026
…uantumNous#4772)

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio

Unifies admin/user ratio display so API key list matches the actual billing ratio.
SamuelSxy pushed a commit to SamuelSxy/new-api-rh that referenced this pull request Jun 7, 2026
…uantumNous#4772)

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio

Unifies admin/user ratio display so API key list matches the actual billing ratio.
fx247562340 pushed a commit to fx247562340/vancine-platform that referenced this pull request Jun 11, 2026
…uantumNous#4772)

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio

Unifies admin/user ratio display so API key list matches the actual billing ratio.
@coderabbitai coderabbitai Bot mentioned this pull request Jun 15, 2026
3 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…uantumNous#4772)

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio

Unifies admin/user ratio display so API key list matches the actual billing ratio.
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…uantumNous#4772)

fix(web/default): use getUserGroups for ratio display to respect GroupGroupRatio

Unifies admin/user ratio display so API key list matches the actual billing ratio.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants