fix: clean up orphaned user-keyed tables in deleteUser (#38511)

### Description
This PR addresses orphaned user-keyed tables during user deletion by
adding the missing models to the `db.DeleteBeans` call in
`services/user/delete.go`:
- `auth_model.TwoFactor` (TOTP secrets)
- `auth_model.WebAuthnCredential` (WebAuthn keys)
- `activities_model.Notification` (Notifications)
- `issues_model.IssueWatch` (Issue watches)

Additionally, it adds corresponding unit test coverage in
`services/user/user_test.go` to assert that these records are cleaned up
successfully.

### Related Issues
Fixes #38510

Signed-off-by: pranav718 <raypranav718@gmail.com>
This commit is contained in:
Knight
2026-07-18 13:08:36 +05:30
committed by GitHub
parent 2cc28ac2a9
commit c6791c3c58
2 changed files with 32 additions and 0 deletions
+4
View File
@@ -96,6 +96,10 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
&user_model.Blocking{BlockeeID: u.ID},
&actions_model.ActionRunnerToken{OwnerID: u.ID},
&actions_model.ActionScopedWorkflowSource{OwnerID: u.ID},
&auth_model.TwoFactor{UID: u.ID},
&auth_model.WebAuthnCredential{UserID: u.ID},
&activities_model.Notification{UserID: u.ID},
&issues_model.IssueWatch{UserID: u.ID},
); err != nil {
return fmt.Errorf("deleteBeans: %w", err)
}