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:
kolaente 2026-03-10 23:37:29 +01:00
parent d196af0503
commit 79a612aa5d
1 changed files with 7 additions and 4 deletions

View File

@ -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 {
return err
}
return notifications.Notify(u, &user.AccountDeletedNotification{
User: u,
}, s)
_, err = s.Where("id = ?", u.ID).Delete(&user.User{})
return err
}
func ensureProjectAdminUser(s *xorm.Session, l *Project) (hadUsers bool, err error) {