dete accounts
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m1s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 2m1s
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -16,6 +16,11 @@ table "accounts" {
|
||||
null = true
|
||||
type = jsonb
|
||||
}
|
||||
column "deleted" {
|
||||
null = true
|
||||
type = boolean
|
||||
default = false
|
||||
}
|
||||
primary_key {
|
||||
columns = [column.id]
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ type DBStorage interface {
|
||||
|
||||
//TODO : remove UpdateAccount, implement UpdateAccountData and UpdateAccountLocalAuthentication
|
||||
UpdateAccount(account Account) error
|
||||
DeleteAccount(id string) error
|
||||
|
||||
Migrate() error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user