fix undeleted content when deleting user (#5509)
This commit is contained in:
parent
2b4f87da46
commit
9cf9a54dca
2 changed files with 18 additions and 11 deletions
|
@ -535,6 +535,7 @@ func DeletePublicKey(doer *User, id int64) (err error) {
|
||||||
if err = sess.Commit(); err != nil {
|
if err = sess.Commit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
sess.Close()
|
||||||
|
|
||||||
return RewriteAllPublicKeys()
|
return RewriteAllPublicKeys()
|
||||||
}
|
}
|
||||||
|
@ -543,6 +544,10 @@ func DeletePublicKey(doer *User, id int64) (err error) {
|
||||||
// Note: x.Iterate does not get latest data after insert/delete, so we have to call this function
|
// Note: x.Iterate does not get latest data after insert/delete, so we have to call this function
|
||||||
// outside any session scope independently.
|
// outside any session scope independently.
|
||||||
func RewriteAllPublicKeys() error {
|
func RewriteAllPublicKeys() error {
|
||||||
|
return rewriteAllPublicKeys(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func rewriteAllPublicKeys(e Engine) error {
|
||||||
//Don't rewrite key if internal server
|
//Don't rewrite key if internal server
|
||||||
if setting.SSH.StartBuiltinServer {
|
if setting.SSH.StartBuiltinServer {
|
||||||
return nil
|
return nil
|
||||||
|
@ -569,7 +574,7 @@ func RewriteAllPublicKeys() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = x.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
|
err = e.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
|
||||||
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
|
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
|
@ -1038,25 +1038,26 @@ func deleteUser(e *xorm.Session, u *User) error {
|
||||||
&EmailAddress{UID: u.ID},
|
&EmailAddress{UID: u.ID},
|
||||||
&UserOpenID{UID: u.ID},
|
&UserOpenID{UID: u.ID},
|
||||||
&Reaction{UserID: u.ID},
|
&Reaction{UserID: u.ID},
|
||||||
|
&TeamUser{UID: u.ID},
|
||||||
|
&Collaboration{UserID: u.ID},
|
||||||
|
&Stopwatch{UserID: u.ID},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return fmt.Errorf("deleteBeans: %v", err)
|
return fmt.Errorf("deleteBeans: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** START: PublicKey *****
|
// ***** START: PublicKey *****
|
||||||
keys := make([]*PublicKey, 0, 10)
|
if _, err = e.Delete(&PublicKey{OwnerID: u.ID}); err != nil {
|
||||||
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 {
|
|
||||||
return fmt.Errorf("deletePublicKeys: %v", err)
|
return fmt.Errorf("deletePublicKeys: %v", err)
|
||||||
}
|
}
|
||||||
|
rewriteAllPublicKeys(e)
|
||||||
// ***** END: PublicKey *****
|
// ***** END: PublicKey *****
|
||||||
|
|
||||||
|
// ***** START: GPGPublicKey *****
|
||||||
|
if _, err = e.Delete(&GPGKey{OwnerID: u.ID}); err != nil {
|
||||||
|
return fmt.Errorf("deleteGPGKeys: %v", err)
|
||||||
|
}
|
||||||
|
// ***** END: GPGPublicKey *****
|
||||||
|
|
||||||
// Clear assignee.
|
// Clear assignee.
|
||||||
if err = clearAssigneeByUserID(e, u.ID); err != nil {
|
if err = clearAssigneeByUserID(e, u.ID); err != nil {
|
||||||
return fmt.Errorf("clear assignee: %v", err)
|
return fmt.Errorf("clear assignee: %v", err)
|
||||||
|
@ -1110,6 +1111,7 @@ func DeleteUser(u *User) (err error) {
|
||||||
if err = sess.Commit(); err != nil {
|
if err = sess.Commit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
sess.Close()
|
||||||
|
|
||||||
return RewriteAllPublicKeys()
|
return RewriteAllPublicKeys()
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue