Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
97eadbef
authored
Jun 18, 2026
by
Seefs
Committed by
GitHub
Jun 18, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(oauth): clear bindings when hard deleting users (#5582)
parent
1414569b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
5 deletions
+14
-5
model/task_cas_test.go
+2
-0
model/user.go
+10
-2
model/user_oauth_binding.go
+2
-3
No files found.
model/task_cas_test.go
View file @
97eadbef
...
@@ -45,6 +45,7 @@ func TestMain(m *testing.M) {
...
@@ -45,6 +45,7 @@ func TestMain(m *testing.M) {
&
SubscriptionPlan
{},
&
SubscriptionPlan
{},
&
SubscriptionOrder
{},
&
SubscriptionOrder
{},
&
UserSubscription
{},
&
UserSubscription
{},
&
UserOAuthBinding
{},
&
PerfMetric
{},
&
PerfMetric
{},
);
err
!=
nil
{
);
err
!=
nil
{
panic
(
"failed to migrate: "
+
err
.
Error
())
panic
(
"failed to migrate: "
+
err
.
Error
())
...
@@ -66,6 +67,7 @@ func truncateTables(t *testing.T) {
...
@@ -66,6 +67,7 @@ func truncateTables(t *testing.T) {
DB
.
Exec
(
"DELETE FROM subscription_orders"
)
DB
.
Exec
(
"DELETE FROM subscription_orders"
)
DB
.
Exec
(
"DELETE FROM subscription_plans"
)
DB
.
Exec
(
"DELETE FROM subscription_plans"
)
DB
.
Exec
(
"DELETE FROM user_subscriptions"
)
DB
.
Exec
(
"DELETE FROM user_subscriptions"
)
DB
.
Exec
(
"DELETE FROM user_oauth_bindings"
)
DB
.
Exec
(
"DELETE FROM perf_metrics"
)
DB
.
Exec
(
"DELETE FROM perf_metrics"
)
})
})
}
}
...
...
model/user.go
View file @
97eadbef
...
@@ -328,8 +328,12 @@ func HardDeleteUserById(id int) error {
...
@@ -328,8 +328,12 @@ func HardDeleteUserById(id int) error {
if
id
==
0
{
if
id
==
0
{
return
errors
.
New
(
"id 为空!"
)
return
errors
.
New
(
"id 为空!"
)
}
}
err
:=
DB
.
Unscoped
()
.
Delete
(
&
User
{},
"id = ?"
,
id
)
.
Error
return
DB
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
deleteUserOAuthBindingsByUserId
(
tx
,
id
);
err
!=
nil
{
return
err
return
err
}
return
tx
.
Unscoped
()
.
Delete
(
&
User
{},
"id = ?"
,
id
)
.
Error
})
}
}
func
inviteUser
(
inviterId
int
)
(
err
error
)
{
func
inviteUser
(
inviterId
int
)
(
err
error
)
{
...
@@ -589,8 +593,12 @@ func (user *User) HardDelete() error {
...
@@ -589,8 +593,12 @@ func (user *User) HardDelete() error {
if
user
.
Id
==
0
{
if
user
.
Id
==
0
{
return
errors
.
New
(
"id 为空!"
)
return
errors
.
New
(
"id 为空!"
)
}
}
err
:=
DB
.
Unscoped
()
.
Delete
(
user
)
.
Error
return
DB
.
Transaction
(
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
deleteUserOAuthBindingsByUserId
(
tx
,
user
.
Id
);
err
!=
nil
{
return
err
return
err
}
return
tx
.
Unscoped
()
.
Delete
(
user
)
.
Error
})
}
}
// ValidateAndFill check password & user status
// ValidateAndFill check password & user status
...
...
model/user_oauth_binding.go
View file @
97eadbef
...
@@ -134,9 +134,8 @@ func DeleteUserOAuthBinding(userId, providerId int) error {
...
@@ -134,9 +134,8 @@ func DeleteUserOAuthBinding(userId, providerId int) error {
return
DB
.
Where
(
"user_id = ? AND provider_id = ?"
,
userId
,
providerId
)
.
Delete
(
&
UserOAuthBinding
{})
.
Error
return
DB
.
Where
(
"user_id = ? AND provider_id = ?"
,
userId
,
providerId
)
.
Delete
(
&
UserOAuthBinding
{})
.
Error
}
}
// DeleteUserOAuthBindingsByUserId deletes all OAuth bindings for a user
func
deleteUserOAuthBindingsByUserId
(
tx
*
gorm
.
DB
,
userId
int
)
error
{
func
DeleteUserOAuthBindingsByUserId
(
userId
int
)
error
{
return
tx
.
Where
(
"user_id = ?"
,
userId
)
.
Delete
(
&
UserOAuthBinding
{})
.
Error
return
DB
.
Where
(
"user_id = ?"
,
userId
)
.
Delete
(
&
UserOAuthBinding
{})
.
Error
}
}
// GetBindingCountByProviderId returns the number of bindings for a provider
// GetBindingCountByProviderId returns the number of bindings for a provider
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment