Skip to content

fix(oauth): clear bindings when hard deleting users - #5582

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/oauth-binding
Jun 18, 2026
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/oauth-binding

Conversation

@seefs001

@seefs001 seefs001 commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
删除用户时删除oauth关系

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • Bug Fixes

    • User account deletion process has been enhanced to properly handle and remove all associated OAuth authentication bindings alongside the user account data, ensuring complete cleanup of user records.
  • Tests

    • Test database setup has been updated to properly initialize OAuth authentication binding tables. Test cleanup routines were improved to reset this data between database integration test executions.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78521e23-9a65-4d9b-9c97-d1018b62d2f5

📥 Commits

Reviewing files that changed from the base of the PR and between 1414569 and 9ccf061.

📒 Files selected for processing (3)
  • model/task_cas_test.go
  • model/user.go
  • model/user_oauth_binding.go

Walkthrough

The exported DeleteUserOAuthBindingsByUserId function is replaced by an unexported deleteUserOAuthBindingsByUserId(tx *gorm.DB, userId int) error that operates within a provided transaction. Both HardDeleteUserById and (*User).HardDelete are updated to open a DB.Transaction that first deletes OAuth bindings for the user and then performs the unscoped user delete. Tests are updated to migrate and truncate the user_oauth_bindings table.

Changes

OAuth binding cascade on user deletion

Layer / File(s) Summary
Unexported transactional OAuth binding delete helper
model/user_oauth_binding.go
Removes DeleteUserOAuthBindingsByUserId(userId int) error and adds the unexported deleteUserOAuthBindingsByUserId(tx *gorm.DB, userId int) error that runs the bulk delete through a supplied transaction handle instead of the global DB. Struct field formatting is also adjusted.
Transactional hard-delete wiring + test setup
model/user.go, model/task_cas_test.go
Both HardDeleteUserById and (*User).HardDelete now open a DB.Transaction that calls deleteUserOAuthBindingsByUserId before the unscoped user delete. The test AutoMigrate list adds &UserOAuthBinding{} and truncateTables adds a DELETE FROM user_oauth_bindings cleanup statement.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop — no orphan rows shall remain,
The bindings once stranded now vanish with flair,
A transaction wraps all, like a warm cozy lair,
Delete user first? No — we tidy with care,
OAuth and user gone cleanly, a pair! ✨

✨ 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 and usage tips.

@seefs001
seefs001 merged commit 97eadbe into QuantumNous:main Jun 18, 2026
1 check passed
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
noah-wung pushed a commit to noah-wung/new-api that referenced this pull request Jul 17, 2026
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
NaturalSelect pushed a commit to NaturalSelect/new-api that referenced this pull request Nov 5, 2026
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.

OIDC 用户被删除后再次登录报错 record not found(user_oauth_bindings 未级联删除)

1 participant