Repository navigation
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Select group during admin invalidation model/subscription.go |
A shared selector chooses the current group when a remaining active subscription grants it. Otherwise, it selects the group from the subscription ending latest. Admin invalidation changes the user’s group only when the current group matches the removed subscription’s upgrade group. |
Apply group selection during scheduled expiry model/subscription.go, model/subscription_auth_test.go |
Scheduled expiry records groups from due subscriptions and updates the user’s group only when the current group matches one of them. Tests cover scheduled expiry and admin invalidation, including cases where a remaining or expired subscription grants the current group. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- QuantumNous/new-api#8138: Changes subscription group references during group-name migration and adds guards for subscription-driven group transitions.
- QuantumNous/new-api#8073: Changes expiry processing and invalidates subscription decision caches after expiration.
- QuantumNous/new-api#8120: Adds expiry-related subscription decision-cache invalidation.
Suggested reviewers: calcium-ion
Merge Risk: 
Minimal · up to d3dcd
-
No actionable issue is established by the supplied evidence; the change appears mergeable after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Check name Status Explanation Description Check Check skipped - CodeRabbit’s high-level summary is enabled. Title check The title names the main change: when a subscription expires, users move to the group of the remaining active subscription. The raw summary confirms this is the core fix in model/subscription.go (Expi… Linked Issues check The only directly linked issue, #8160, is closed. It supplies historical context only. No active directly linked targets remain, so no linked-issue coding requirements apply. For reference, the diff a…Out of Scope Changes check The whole-PR diff against merge base 70e6af6 touches only model/subscription.goandmodel/subscription_auth_test.go. Both files match the PR's Files table. Themodel/subscription.gohunks change…Full details: Title check
-
Explanation
The title names the main change: when a subscription expires, users move to the group of the remaining active subscription. The raw summary confirms this is the core fix in model/subscription.go (ExpireDueSubscriptions and downgradeUserGroupForSubscriptionTx), with a supporting test. The title is specific and follows the conventional-commit style. It is 77 characters, within a readable length.
Full details: Linked Issues check
-
Explanation
The only directly linked issue,
#8160, is closed. It supplies historical context only. No active directly linked targets remain, so no linked-issue coding requirements apply. For reference, the diff at head d3dcd6f still implements the behavior described in#8160. Inmodel/subscription.go,ExpireDueSubscriptionsanddowngradeUserGroupForSubscriptionTxnow call the newactiveSubscriptionUpgradeGroupTx. The user moves to the remaining subscription's group only when the current group was granted by a subscription expiring now. A group granted by no expiring subscription is left unchanged. The new testTestSubscriptionExpiryMovesUserToRemainingSubscriptionGroupcovers the scheduled and admin paths. The author reports that it passes; this assessment did not run it.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff against merge base 70e6af6 touches only
model/subscription.goandmodel/subscription_auth_test.go. Both files match the PR's Files table. Themodel/subscription.gohunks change only the remaining-subscription lookup, the group update, and the due-group capture in the scheduled expiry and admin downgrade paths. They also add theslicesimport and the helper function. Every hunk serves the expiry group-selection behavior described in#8160and the PR description. The test hunk covers the same behavior. No unrelated refactor, feature, or configuration change appears in the diff.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
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.
I’m a rabbit watching plans expire,
I hop as groups change their attire.
The latest plan may set the way,
A granted group can choose to stay.
Then I tuck the tests away.
Agent
Links
User request
Out of scope — refuse
Open gate — do not open unless all are satisfied
go buildor tests passed: yesKind
Issue facts
model/subscription.go; reproduced by a unit test onmain.Change
ExpireDueSubscriptionsanddowngradeUserGroupForSubscriptionTxused to return as soon as any other active subscription had anupgrade_group. Now they ask which group the remaining subscriptions grant (activeSubscriptionUpgradeGroupTx):expiredin the scheduled path, the cancelled or deletedsubin the admin path. A group no expiring subscription granted, for example one an admin assigned, is left alone, even if an older expired subscription once granted it.The path with no remaining upgraded subscription is unchanged. Queries use GORM only.
Research
Duplicate / prior art
subscription downgrade,ExpireDueSubscriptions,downgradeUserGroupForSubscriptionTx,subscription upgrade_group expire,订阅 到期 分组,订阅 过期 用户组prev_user_group) and fix: correct chained subscription expiry downgrade #5924 (several chained subscriptions expiring in one scan) both keep the early return while another upgraded subscription is active; fix(subscription): revert user group on expiry across renewals and stacked plans #5560 has a test asserting it. This PR changes only that branch, so it is independent of both; the touched lines overlap and whichever lands second needs a rebase.Docs and code
/en/docs/guide/feature-guide/user/wallet, "Viewing subscription status" item 2: with other active upgrade subscriptions, "the current group may be maintained; the final group will be processed in conjunction with other subscription statuses".ExpireDueSubscriptions(scheduled expiry) anddowngradeUserGroupForSubscriptionTx(AdminInvalidateUserSubscription,AdminDeleteUserSubscription) share the same early return, so both are changed.Alternatives considered
Files
model/subscription.gomodel/subscription_auth_test.goBehavior
pro, expired) + B (basic, active), user inpro-> staysprountil B ends.basic. If B also grantedpro, the user stayspro. A group no expiring subscription granted is unchanged. With no remaining subscription, the existing downgrade logic applies.Verification
main70e6af6with only the new test:go test ./model/ -run 'TestSubscriptionExpiryMovesUserToRemainingSubscriptionGroup$' -count=1->FAIL .../scheduled/remaining_lower_tierand.../admin/remaining_lower_tier,expected: "basic" actual: "pro".go test ./model/ -count=1->ok github.com/QuantumNous/new-api/model 12.975s;go vet ./model/clean;gofmt -l model/empty.DBat each engine:--- PASSon both.model/subscription_auth_test.go.WHERE/ORDER BY/COUNTthrough GORM. The local MySQL/PostgreSQL harness is not part of the PR.Risks
Scope check
Summary by CodeRabbit