Skip to content

fix(oauth): persist inviter for OAuth registrations#5766

Open
zhangzhichaolove wants to merge 2 commits into
QuantumNous:mainfrom
zhangzhichaolove:fixbug
Open

fix(oauth): persist inviter for OAuth registrations#5766
zhangzhichaolove wants to merge 2 commits into
QuantumNous:mainfrom
zhangzhichaolove:fixbug

Conversation

@zhangzhichaolove

@zhangzhichaolove zhangzhichaolove commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。
  • 当前 git 用户不是仓库历史核心提交者之一。本次变更由 AI 辅助生成,提交前请人工复核。

📝 变更描述 / Description

OAuth 注册新用户时,后端已经从 session 中解析邀请人的 aff 并得到 inviterId,但事务插入路径 InsertWithTx 没有把该值保存到用户的 inviter_id 字段,导致 OAuth 注册用户缺少邀请归属。

本次修改让 InsertWithTx 在创建用户前写入 user.InviterId = inviterId,使 OAuth 注册与普通密码注册保持一致。同时新增模型层回归测试,覆盖有邀请人和无邀请人两种 OAuth 用户创建场景。

🚀 变更类型 / 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

本地验证通过:

go test ./model

结果:

ok  	github.com/QuantumNous/new-api/model	1.451s

Summary by CodeRabbit

  • Bug Fixes
    • Fixed OAuth user creation so inviter information is now saved correctly when accounts are created within an existing transaction.
    • Improved coverage with automated tests that confirm the stored inviter value is correct for both cases: with an inviter and without an inviter.

@coderabbitai

coderabbitai Bot commented Jun 27, 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: 2fa4eb08-0bde-4a77-a553-513af84cc58e

📥 Commits

Reviewing files that changed from the base of the PR and between a5ab0f8 and 95f7e64.

📒 Files selected for processing (1)
  • model/user.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • model/user.go

Walkthrough

The transactional OAuth user insert now assigns inviterId before persisting the user. A new test inserts users with and without an inviter and verifies the stored inviter_id value.

Changes

OAuth inviter persistence

Layer / File(s) Summary
Persist inviter id in InsertWithTx
model/user.go, model/user_oauth_test.go
InsertWithTx now copies inviterId onto the User before tx.Create, and a transactional test verifies the stored inviter_id for cases with and without an inviter.

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

Poem

🐇 A hop, a tx, a tiny cue,
The inviter id now travels through.
Insert, then read, the trail stays clear,
The bunny says: “it’s stored right here!”

🚥 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: persisting inviter data during OAuth registrations.
Linked Issues check ✅ Passed The code now stores inviterId in InsertWithTx and adds regression tests, matching the reported OAuth inviter-loss issue.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to the OAuth inviter fix and its regression tests.
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.

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.

GitHub OAuth 注册时邀请人无法获得额度

1 participant