Skip to content

fix(pricing): trim enable_groups to the user's usable groups - #6176

Open
Dashsoap wants to merge 1 commit into
QuantumNous:mainfrom
Dashsoap:fix/pricing-usable-enable-groups
Open

fix(pricing): trim enable_groups to the user's usable groups#6176
Dashsoap wants to merge 1 commit into
QuantumNous:mainfrom
Dashsoap:fix/pricing-usable-enable-groups

Conversation

@Dashsoap

@Dashsoap Dashsoap commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

GetPricing 之前只按用户可用分组过滤返回哪些模型(#4123),但每个模型条目里的 enable_groups 仍是渠道原始分组列表。default 主题会在模型详情页底部「分组」栏和表格视图分组列原样渲染,导致对用户隐藏的分组名(不在 UserUsableGroups、或被 -:分组 特殊规则移除)虽然选不了,却仍然展示了出来。

本次在 filterPricingByUsableGroups 里把每个条目的 enable_groups 裁剪为与用户可用分组的交集,这样能生效的原因是 default 主题的分组徽章、表格分组列都直接读这个字段,服务端裁剪后两个主题一起修好:

  • all 的条目保持原有列表与语义不变;
  • 交集为空的条目本来就不会返回,返回的模型集合与之前完全一致,只有 enable_groups 字段内容变化;
  • 遍历中的 item 是共享定价缓存的值拷贝,写入的是新建 slice,不会改动缓存;
  • classic 主题前端本来就按交集展示(ModelPricingTable.jsx),行为不变。

按仓库贡献规范说明:本次修改在 AI 辅助下完成,我已逐行审阅代码,并在本地构建后按下方运行证明实测验证(前后端同配置对照 + 单测)。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

新增单测 controller/pricing_test.go(覆盖:交集裁剪、all 保持原样、缓存不被改动、空输入):

$ go test ./controller/ -run TestFilterPricingByUsableGroups -v
=== RUN   TestFilterPricingByUsableGroupsTrimsEnableGroups
--- PASS: TestFilterPricingByUsableGroupsTrimsEnableGroups (0.00s)
=== RUN   TestFilterPricingByUsableGroupsEmptyInputs
--- PASS: TestFilterPricingByUsableGroupsEmptyInputs (0.00s)
PASS
ok      github.com/QuantumNous/new-api/controller       0.874s

本地实测(UserUsableGroups 只有 default/vip,渠道分组 default,internal):

修复前——「按分组定价」只有 default,底部「分组」却显示 internal:

修复前

修复后——同一份配置与前端构建,只换后端,internal 不再展示:

修复后

/api/pricing 响应对比(同一请求):

-  "enable_groups": ["default", "internal"]
+  "enable_groups": ["default"]

Summary by CodeRabbit

  • Bug Fixes

    • Pricing results now include only groups available to the current user.
    • Entries without usable groups are excluded.
    • Shared pricing data remains unchanged between requests.
  • Tests

    • Added coverage for group filtering, empty inputs, and preserving cached pricing data.

GetPricing already filters which models are returned by the user's
usable groups, but each pricing item still carried the raw channel
group list in enable_groups. The default theme renders that list
as-is (model detail Groups section, model card badge, table column),
so groups hidden from a user via UserUsableGroups or a -:group
special rule were still displayed even though they could not be
selected. The classic theme already intersects enable_groups with
usable groups on the client.

Trim enable_groups server-side to the intersection with the user's
usable groups so hidden group names are no longer exposed by the
API. Entries enabled for "all" groups keep their original list, and
the shared pricing cache is never mutated.
@coderabbitai

coderabbitai Bot commented Jul 13, 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: 84a8282e-ceec-4744-a754-4eb84d05d533

📥 Commits

Reviewing files that changed from the base of the PR and between 7c28993 and ebadf3d.

📒 Files selected for processing (2)
  • controller/pricing.go
  • controller/pricing_test.go

Walkthrough

Pricing filtering now trims each entry’s EnableGroup values to usable groups, skips entries with no matches, preserves shared input data, and adds tests for normal and empty inputs.

Changes

Pricing group filtering

Layer / File(s) Summary
Filter enable groups and validate results
controller/pricing.go, controller/pricing_test.go
filterPricingByUsableGroups creates per-item filtered groups, excludes entries without usable groups, and tests trimming, ordering, input preservation, and empty inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: bbbugg, calcium-ion, seefs001

Poem

A rabbit trims the groups with care,
Keeping only those users share.
The cached list stays neat and bright,
Empty paths return just right.
“Hop!” says the test, “the leak takes flight!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: trimming pricing enable_groups to the user's usable groups.
Linked Issues check ✅ Passed The PR filters /api/pricing enable_groups to usable groups and adds tests covering the leak fix and empty inputs.
Out of Scope Changes check ✅ Passed The changes stay focused on pricing-group filtering and related tests without introducing unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

JacksonsY added a commit to JacksonsY/new-api that referenced this pull request Jul 19, 2026
移植自上游 PR QuantumNous#6176(issue QuantumNous#6175)。原逻辑「有交集就整条返回」,
把用户无权使用的分组名原样带给前端分组徽章——本 fork 有团队
计价分组与代理分销分组,内部分组命名泄露面更大。改为按可用
分组求交集后重建 EnableGroup;item 是共享定价缓存的值拷贝,
赋新 slice 不会污染缓存。带 "all" 的条目保持原语义整条放行。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
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.

模型广场仍展示用户不可用的分组:/api/pricing 的 enable_groups 未按可用分组过滤

1 participant