diff options
author | Unknwon <u@gogs.io> | 2016-07-26 17:26:48 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-07-26 17:26:48 +0800 |
commit | 2d76de2574d2e3734ed8e566845042e6fb281a6e (patch) | |
tree | 97e1bea2d1571b08a831aa8a73fea2793c6a6c17 /models/user.go | |
parent | 4d8b9055412abc3f135aa2fb4370f2d8c8246dbf (diff) | |
download | gitea-2d76de2574d2e3734ed8e566845042e6fb281a6e.tar.gz gitea-2d76de2574d2e3734ed8e566845042e6fb281a6e.zip |
#3281 fix x.Iterate returns nothing inside session scope with SQLite3
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/models/user.go b/models/user.go index a22162dc2d..5e9b60addb 100644 --- a/models/user.go +++ b/models/user.go @@ -768,10 +768,13 @@ func deleteUser(e *xorm.Session, u *User) error { if err = e.Find(&keys, &PublicKey{OwnerID: u.ID}); err != nil { return fmt.Errorf("get all public keys: %v", err) } - for _, key := range keys { - if err = deletePublicKey(e, key.ID); err != nil { - return fmt.Errorf("deletePublicKey: %v", err) - } + + keyIDs := make([]int64, len(keys)) + for i := range keys { + keyIDs[i] = keys[i].ID + } + if err = deletePublicKeys(e, keyIDs...); err != nil { + return fmt.Errorf("deletePublicKeys: %v", err) } // ***** END: PublicKey ***** @@ -788,7 +791,6 @@ func deleteUser(e *xorm.Session, u *User) error { // Note: There are something just cannot be roll back, // so just keep error logs of those operations. - RewriteAllPublicKeys() os.RemoveAll(UserPath(u.Name)) os.Remove(u.CustomAvatarPath()) @@ -809,15 +811,20 @@ func DeleteUser(u *User) (err error) { return err } - return sess.Commit() + if err = sess.Commit(); err != nil { + return err + } + + return RewriteAllPublicKeys() } // DeleteInactivateUsers deletes all inactivate users and email addresses. func DeleteInactivateUsers() (err error) { users := make([]*User, 0, 10) - if err = x.Where("is_active=?", false).Find(&users); err != nil { + if err = x.Where("is_active = ?", false).Find(&users); err != nil { return fmt.Errorf("get all inactive users: %v", err) } + // FIXME: should only update authorized_keys file once after all deletions. for _, u := range users { if err = DeleteUser(u); err != nil { // Ignore users that were set inactive by admin. @@ -828,7 +835,7 @@ func DeleteInactivateUsers() (err error) { } } - _, err = x.Where("is_activated=?", false).Delete(new(EmailAddress)) + _, err = x.Where("is_activated = ?", false).Delete(new(EmailAddress)) return err } |