diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-12-19 00:26:26 +0800 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-12-18 11:26:26 -0500 |
commit | fe55ab2a6806b6a7c114378c0436bc59a31646d0 (patch) | |
tree | 43e0566e550b38596c6fb2ec6c0bf5adeeaad7f4 /models/user.go | |
parent | e726e4b828e9592085e6cf717a2e6c29b1c2d472 (diff) | |
download | gitea-fe55ab2a6806b6a7c114378c0436bc59a31646d0.tar.gz gitea-fe55ab2a6806b6a7c114378c0436bc59a31646d0.zip |
fix forgot removed records when deleting user (#5429)
* fix forgot removed records when deleting user
* fix migration
* fix rewritekey lock on sqlite
* remove unused codes
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/models/user.go b/models/user.go index 8f1b170b0d..a30e0d8e52 100644 --- a/models/user.go +++ b/models/user.go @@ -1015,25 +1015,26 @@ func deleteUser(e *xorm.Session, u *User) error { &EmailAddress{UID: u.ID}, &UserOpenID{UID: u.ID}, &Reaction{UserID: u.ID}, + &TeamUser{UID: u.ID}, + &Collaboration{UserID: u.ID}, + &Stopwatch{UserID: u.ID}, ); err != nil { return fmt.Errorf("deleteBeans: %v", err) } // ***** START: PublicKey ***** - keys := make([]*PublicKey, 0, 10) - if err = e.Find(&keys, &PublicKey{OwnerID: u.ID}); err != nil { - return fmt.Errorf("get all public keys: %v", err) - } - - keyIDs := make([]int64, len(keys)) - for i := range keys { - keyIDs[i] = keys[i].ID - } - if err = deletePublicKeys(e, keyIDs...); err != nil { + if _, err = e.Delete(&PublicKey{OwnerID: u.ID}); err != nil { return fmt.Errorf("deletePublicKeys: %v", err) } + rewriteAllPublicKeys(e) // ***** END: PublicKey ***** + // ***** START: GPGPublicKey ***** + if _, err = e.Delete(&GPGKey{OwnerID: u.ID}); err != nil { + return fmt.Errorf("deleteGPGKeys: %v", err) + } + // ***** END: GPGPublicKey ***** + // Clear assignee. if err = clearAssigneeByUserID(e, u.ID); err != nil { return fmt.Errorf("clear assignee: %v", err) @@ -1084,11 +1085,7 @@ func DeleteUser(u *User) (err error) { return err } - if err = sess.Commit(); err != nil { - return err - } - - return RewriteAllPublicKeys() + return sess.Commit() } // DeleteInactivateUsers deletes all inactivate users and email addresses. |