fix: send account deletion notification before deleting user row
When deleting a user via CLI (`vikunja user delete <id> -n`), the user row was deleted first, then `notifications.Notify` was called. But `Notify` calls `User.ShouldNotify()` which queries the database to check the user's status — and since the row was already deleted within the same transaction, it returned `ErrUserDoesNotExist`. Move the notification call before the `DELETE` so the user row still exists when `ShouldNotify` checks it. Closes go-vikunja/vikunja#2335
This commit is contained in:
parent
d196af0503
commit
79a612aa5d
|
|
@ -169,14 +169,17 @@ func DeleteUser(s *xorm.Session, u *user.User) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.Where("id = ?", u.ID).Delete(&user.User{})
|
// Notify before deleting the user row, because ShouldNotify will try to
|
||||||
|
// look up the user and fail if the row is already gone.
|
||||||
|
err = notifications.Notify(u, &user.AccountDeletedNotification{
|
||||||
|
User: u,
|
||||||
|
}, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifications.Notify(u, &user.AccountDeletedNotification{
|
_, err = s.Where("id = ?", u.ID).Delete(&user.User{})
|
||||||
User: u,
|
return err
|
||||||
}, s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureProjectAdminUser(s *xorm.Session, l *Project) (hadUsers bool, err error) {
|
func ensureProjectAdminUser(s *xorm.Session, l *Project) (hadUsers bool, err error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue