feat: subscription plan group restriction#4079
feat: subscription plan group restriction#4079po1onius wants to merge 1 commit intoQuantumNous:mainfrom
Conversation
WalkthroughThe changes add group-based matching to subscription consumption. A new Changes
Sequence DiagramsequenceDiagram
participant Relay as Relay Request
participant BillingSession as BillingSession
participant FundingSource as SubscriptionFunding
participant Model as Model Layer
Relay->>BillingSession: Request with UsingGroup
BillingSession->>FundingSource: Create SubscriptionFunding(usingGroup)
FundingSource->>Model: PreConsumeUserSubscription(..., usingGroup)
Model->>Model: subscriptionMatchesModelGroup()
alt Group matches
Model->>Model: Consume subscription quota
Model-->>FundingSource: PreConsumeResult
else No matching group
Model-->>FundingSource: "no active subscription" error
end
FundingSource-->>BillingSession: Result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d0538cf-326a-41fb-bf2b-37aecad2955d
📒 Files selected for processing (3)
model/subscription.goservice/billing_session.goservice/funding_source.go
| func subscriptionMatchesModelGroup(sub *UserSubscription, modelName string, usingGroup string) bool { | ||
| if sub == nil { | ||
| return false | ||
| } | ||
| upgradeGroup := strings.TrimSpace(sub.UpgradeGroup) | ||
| if upgradeGroup == "" { | ||
| return true | ||
| } | ||
| usingGroup = strings.TrimSpace(usingGroup) | ||
| if usingGroup != "" && usingGroup != "auto" { | ||
| return usingGroup == upgradeGroup | ||
| } | ||
| modelGroups := GetModelEnableGroups(modelName) | ||
| for _, group := range modelGroups { | ||
| if strings.TrimSpace(group) == upgradeGroup { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
There was a problem hiding this comment.
Use AllowedGroups for eligibility; UpgradeGroup is a different concern.
This matcher makes every restricted-but-non-upgrading plan universally match (UpgradeGroup == "" returns true), and it also turns existing upgrade-only plans into group-restricted ones, which breaks the backward-compatibility goal. A single UpgradeGroup value also cannot represent the issue's comma-separated multi-group allowlist, so the restriction needs to be persisted and matched via AllowedGroups on the UserSubscription snapshot instead.
close: #3388
总结
就像该issue描述的那样,当前的订阅机制欠缺限制,无法限制订阅计划能够使用的模型,比如创建针对模型A的订阅时,用户能够使用订阅的额度来使用模型B。该pr补充了上升分组的能力,当用户订阅后使用对应上升分组的模型时会扣除订阅额度,但用户使用对应上升分组之外的模型时,使用余额扣费。
验证
已在本地部署,创建测试订阅,并观察使用日志,效果达到预期
Summary by CodeRabbit
New Features
Bug Fixes