From 30bed5771196ba818a2cdfd53ebff009d09bbee6 Mon Sep 17 00:00:00 2001 From: braginini Date: Wed, 17 Apr 2024 19:12:53 +0200 Subject: [PATCH] Fix account deletion --- management/server/sqlite_store.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/management/server/sqlite_store.go b/management/server/sqlite_store.go index 68c809da4..cf1eb3f85 100644 --- a/management/server/sqlite_store.go +++ b/management/server/sqlite_store.go @@ -281,6 +281,19 @@ func (s *SqliteStore) SaveAccount(account *Account) error { func (s *SqliteStore) DeleteAccount(account *Account) error { start := time.Now() + account.UsersG = make([]User, 0, len(account.Users)) + for id, user := range account.Users { + user.Id = id + //we need an explicit reference to an account as it is missing for some reason + user.AccountID = account.Id + user.PATsG = make([]PersonalAccessToken, 0, len(user.PATs)) + for id, pat := range user.PATs { + pat.ID = id + user.PATsG = append(user.PATsG, *pat) + } + account.UsersG = append(account.UsersG, *user) + } + err := s.db.Transaction(func(tx *gorm.DB) error { result := tx.Select(clause.Associations).Delete(account.Policies, "account_id = ?", account.Id) if result.Error != nil {