diff options
author | Frédéric Guillot <fred@miniflux.net> | 2019-11-17 22:13:16 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2019-11-17 23:11:59 -0800 |
commit | 7b995044b48e0c18a6b345f6d784191ac97ad264 (patch) | |
tree | 44f21744dec24c93bc5068640fe99f9353539708 | |
parent | e878dca3d74e1b8644d56e4f717b0a8e0362e888 (diff) |
Make sure to remove integration settings when removing a user
-rw-r--r-- | storage/user.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/storage/user.go b/storage/user.go index 39b50ef..5c14644 100644 --- a/storage/user.go +++ b/storage/user.go @@ -6,7 +6,6 @@ package storage // import "miniflux.app/storage" import ( "database/sql" - "errors" "fmt" "strings" @@ -288,18 +287,23 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err // RemoveUser deletes a user. func (s *Storage) RemoveUser(userID int64) error { - result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID) + ts, err := s.db.Begin() if err != nil { - return fmt.Errorf(`store: unable to remove this user: %v`, err) + return fmt.Errorf(`store: unable to start transaction: %v`, err) } - count, err := result.RowsAffected() - if err != nil { - return fmt.Errorf(`store: unable to remove this user: %v`, err) + if _, err := ts.Exec(`DELETE FROM users WHERE id=$1`, userID); err != nil { + ts.Rollback() + return fmt.Errorf(`store: unable to remove user #%d: %v`, userID, err) + } + + if _, err := ts.Exec(`DELETE FROM integrations WHERE user_id=$1`, userID); err != nil { + ts.Rollback() + return fmt.Errorf(`store: unable to remove integration settings for user #%d: %v`, userID, err) } - if count == 0 { - return errors.New(`store: nothing has been removed`) + if err := ts.Commit(); err != nil { + return fmt.Errorf(`store: unable to commit transaction: %v`, err) } return nil |