dete accounts
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m1s

This commit is contained in:
Arnaud Delcasse
2026-01-13 15:33:38 +01:00
parent c958736472
commit 44f5a3d182
10 changed files with 221 additions and 28 deletions

View File

@@ -6,6 +6,7 @@ type Account struct {
Authentication AccountAuth `json:"-" bson:"authentication"`
Data map[string]any `json:"data"`
Metadata map[string]any `json:"metadata"`
Deleted bool `json:"deleted" bson:"deleted"`
}
type AccountAuth struct {

View File

@@ -193,6 +193,20 @@ func (s MongoDBStorage) UpdateAccount(account Account) error {
return nil
}
func (s MongoDBStorage) DeleteAccount(id string) error {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
update := bson.M{
"$set": bson.M{"deleted": true},
"$unset": bson.M{"authentication": ""},
}
if _, err := collection.UpdateOne(context.TODO(), bson.M{"_id": id}, update); err != nil {
log.Error().Err(err).Msg("")
return err
}
return nil
}
func (s MongoDBStorage) Migrate() error {
log.Error().Msg("no migration")
return nil

View File

@@ -420,6 +420,34 @@ func (psql PostgresqlStorage) UpdateAccount(account Account) error {
return nil
}
func (psql PostgresqlStorage) DeleteAccount(id string) error {
tx, err := psql.DbConnection.BeginTx(context.Background(), nil)
if err != nil {
return err
}
defer tx.Rollback()
// Delete authentication info
req := fmt.Sprintf(`DELETE FROM %s WHERE account_id = $1`, psql.Tables["accounts_auth_local"])
_, err = tx.Exec(req, id)
if err != nil {
return err
}
// Mark account as deleted
req = fmt.Sprintf(`UPDATE %s SET deleted = true WHERE id = $1`, psql.Tables["accounts"])
_, err = tx.Exec(req, id)
if err != nil {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
}
func (psql PostgresqlStorage) Migrate() error {
ctx := context.Background()
driver, err := postgres.Open(psql.DbConnection)

View File

@@ -16,6 +16,11 @@ table "accounts" {
null = true
type = jsonb
}
column "deleted" {
null = true
type = boolean
default = false
}
primary_key {
columns = [column.id]
}

View File

@@ -37,6 +37,7 @@ type DBStorage interface {
//TODO : remove UpdateAccount, implement UpdateAccountData and UpdateAccountLocalAuthentication
UpdateAccount(account Account) error
DeleteAccount(id string) error
Migrate() error
}