Skip to content

Commit

Permalink
Merge pull request #1655 from memphisdev/bugfix-RND-490-delete-accoun…
Browse files Browse the repository at this point in the history
…t-error

bugfix-RND-490-delete-account-error
  • Loading branch information
daniel-davidd authored Jan 29, 2024
2 parents 7f76690 + 488d742 commit 842cf68
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
46 changes: 46 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8407,3 +8407,49 @@ func RemoveRoleAndPermissions(roleID []int, tenantName string) error {

return nil
}

func RemovePermissionsByTenant(tenantName string) error {
ctx, cancelfunc := context.WithTimeout(context.Background(), DbOperationTimeout*time.Second)
defer cancelfunc()
tenantName = strings.ToLower(tenantName)
conn, err := MetadataDbClient.Client.Acquire(ctx)
if err != nil {
return err
}
defer conn.Release()

query := `DELETE FROM permissions WHERE tenant_name = $1`
stmt, err := conn.Conn().Prepare(ctx, "remove_permissions_by_tenant", query)
if err != nil {
return err
}
_, err = conn.Conn().Query(ctx, stmt.Name, tenantName)
if err != nil {
return err
}

return nil
}

func RemoveRolesByTenant(tenantName string) error {
ctx, cancelfunc := context.WithTimeout(context.Background(), DbOperationTimeout*time.Second)
defer cancelfunc()
tenantName = strings.ToLower(tenantName)
conn, err := MetadataDbClient.Client.Acquire(ctx)
if err != nil {
return err
}
defer conn.Release()

query := `DELETE FROM roles WHERE tenant_name = $1`
stmt, err := conn.Conn().Prepare(ctx, "remove_roles_by_tenant", query)
if err != nil {
return err
}
_, err = conn.Conn().Query(ctx, stmt.Name, tenantName)
if err != nil {
return err
}

return nil
}
10 changes: 10 additions & 0 deletions server/memphis_handlers_user_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ func removeTenantResources(tenantName string, user models.User) error {
return err
}

err = db.RemovePermissionsByTenant(tenantName)
if err != nil {
return err
}

err = db.RemoveRolesByTenant(tenantName)
if err != nil {
return err
}

err = db.RemoveStationsByTenant(tenantName)
if err != nil {
return err
Expand Down

0 comments on commit 842cf68

Please sign in to comment.