Skip to content

Commit 56716f5

Browse files
author
Gusted
authored
Prevent dangling user redirects (#21856) (#21859)
- Backport #21856 - It's possible that the `user_redirect` table contains a user id that no longer exists. - Delete a user redirect upon deleting the user. - Add a check for these dangling user redirects to check-db-consistency.
1 parent 65b5c8e commit 56716f5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: models/user.go

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) {
8787
&user_model.Setting{UserID: u.ID},
8888
&pull_model.AutoMerge{DoerID: u.ID},
8989
&pull_model.ReviewState{UserID: u.ID},
90+
&user_model.Redirect{RedirectUserID: u.ID},
9091
); err != nil {
9192
return fmt.Errorf("deleteBeans: %v", err)
9293
}

Diff for: modules/doctor/dbconsistency.go

+3
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
205205
// find stopwatches without existing issue
206206
genericOrphanCheck("Orphaned Stopwatches without existing Issue",
207207
"stopwatch", "issue", "stopwatch.issue_id=`issue`.id"),
208+
// find redirects without existing user.
209+
genericOrphanCheck("Orphaned Redirects without existing redirect user",
210+
"user_redirect", "user", "user_redirect.redirect_user_id=`user`.id"),
208211
)
209212

210213
for _, c := range consistencyChecks {

0 commit comments

Comments
 (0)