Repository navigation
fix: count invites when inviter reward is zero - #6363
Sunshine-JamesHu wants to merge 1 commit into
Conversation
WalkthroughInvitation finalization now records inviter counts independently of reward quota. Reward counters, invitee quota, and related logs remain conditional on payment compliance. New table-driven coverage validates password and OAuth registration paths. ChangesInvitation tracking and rewards
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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
🧹 Nitpick comments (1)
model/user_invite_test.go (1)
25-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an OAuth case for compliance-confirmed + zero reward.
Case 1 covers password registration with
complianceConfirmed: trueand zero reward (the exact issue#6362scenario). Case 2 covers OAuth but withcomplianceConfirmedleftfalse, which exercises a different branch (early return before the reward block) than case 1. Since the PR objective states the bug affects both password and OAuth flows, consider adding a table entry withoauth: true, complianceConfirmed: trueand zeroinviterReward/inviteeRewardto directly mirror the reported OAuth scenario.🤖 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 `@model/user_invite_test.go` around lines 25 - 52, Add a table entry in the user invite tests covering OAuth registration with complianceConfirmed set to true and both rewards left at zero. Keep the case distinct from the existing OAuth non-compliance scenario so it exercises the same reward-processing branch as the password compliance-confirmed case.
🤖 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 `@model/user.go`:
- Around line 693-717: Update User.finalizeInvitation to stop the reward flow
immediately when recordUserInvite fails, rather than continuing to credit or log
rewards. Check and propagate the error from IncreaseUserQuota for the invitee,
and emit the “使用邀请码赠送” log only after that credit succeeds; retain the inviter
reward log only when recordUserInvite succeeded and the compliance conditions
apply.
---
Nitpick comments:
In `@model/user_invite_test.go`:
- Around line 25-52: Add a table entry in the user invite tests covering OAuth
registration with complianceConfirmed set to true and both rewards left at zero.
Keep the case distinct from the existing OAuth non-compliance scenario so it
exercises the same reward-processing branch as the password compliance-confirmed
case.
🪄 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: f4f724b4-a9ed-468a-9810-10dcc51e5507
📒 Files selected for processing (2)
model/user.gomodel/user_invite_test.go
| func (user *User) finalizeInvitation(inviterId int) { | ||
| if inviterId == 0 { | ||
| return | ||
| } | ||
|
|
||
| rewardQuota := 0 | ||
| complianceConfirmed := operation_setting.IsPaymentComplianceConfirmed() | ||
| if complianceConfirmed { | ||
| rewardQuota = common.QuotaForInviter | ||
| } | ||
| if err := recordUserInvite(inviterId, rewardQuota); err != nil { | ||
| common.SysError(fmt.Sprintf("failed to record invite for inviter %d: %v", inviterId, err)) | ||
| } | ||
|
|
||
| if !complianceConfirmed { | ||
| return | ||
| } | ||
| if common.QuotaForInvitee > 0 { | ||
| _ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true) | ||
| RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee))) | ||
| } | ||
| if common.QuotaForInviter > 0 { | ||
| RecordLog(inviterId, LogTypeSystem, fmt.Sprintf("邀请用户赠送 %s", logger.LogQuota(common.QuotaForInviter))) | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reward logs and invitee credit fire even when the inviter update fails.
If recordUserInvite fails (e.g. inviter not found), the error is only logged via SysError — execution continues to credit the invitee's quota and unconditionally records "邀请用户赠送" / "使用邀请码赠送" logs as if the reward transaction succeeded. Similarly, IncreaseUserQuota's error is discarded (_ =) and the "credited" log still fires regardless. This can leave an audit trail claiming a reward was granted when it wasn't, and the invitee could receive quota funded by a reward that never landed on the inviter's side.
🐛 Proposed fix to align logs with actual outcomes
if err := recordUserInvite(inviterId, rewardQuota); err != nil {
common.SysError(fmt.Sprintf("failed to record invite for inviter %d: %v", inviterId, err))
}
if !complianceConfirmed {
return
}
if common.QuotaForInvitee > 0 {
- _ = IncreaseUserQuota(user.Id, common.QuotaForInvitee, true)
- RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
+ if err := IncreaseUserQuota(user.Id, common.QuotaForInvitee, true); err != nil {
+ common.SysError(fmt.Sprintf("failed to increase invitee %d quota: %v", user.Id, err))
+ } else {
+ RecordLog(user.Id, LogTypeSystem, fmt.Sprintf("使用邀请码赠送 %s", logger.LogQuota(common.QuotaForInvitee)))
+ }
}🤖 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 `@model/user.go` around lines 693 - 717, Update User.finalizeInvitation to stop
the reward flow immediately when recordUserInvite fails, rather than continuing
to credit or log rewards. Check and propagate the error from IncreaseUserQuota
for the invitee, and emit the “使用邀请码赠送” log only after that credit succeeds;
retain the inviter reward log only when recordUserInvite succeeded and the
compliance conditions apply.
51fdfc5 to
2b6f1df
Compare
The one-time affiliate import backfills old relations with the legacy source. Treat it as a recorded binding channel so the administrator statistics accept it as a filter and the imported relations are counted, and offer the matching filter option in the wallet frontend. The transfer attempt test covers the per-attempt idempotency key and the refused-transfer path of the affiliate hook. Inspired-by: QuantumNous#6362 Inspired-by: QuantumNous#6363 Local tests not run (CI-only session).
Important
📝 变更描述 / Description
将邀请关系计数与邀请奖励发放解耦。有效邀请现在始终原子增加邀请人的 aff_count;只有奖励额度大于 0 时才增加 aff_quota 和 aff_history。密码注册与 OAuth 注册共用同一收尾逻辑,避免两个入口再次出现行为差异。
新增表驱动回归测试,覆盖邀请人奖励为 0、未确认支付合规时不发奖励,以及奖励正常发放三种场景。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Summary by CodeRabbit