From d0506aa03607985bd7dc8976acd789cdc82bc77f Mon Sep 17 00:00:00 2001 From: shohamroditimemphis Date: Sat, 17 Jun 2023 13:08:27 +0300 Subject: [PATCH 1/2] changes for cloud --- db/db.go | 25 +++++++++++++++++++++++++ server/background_tasks.go | 2 +- server/memphis_cloud.go | 9 +-------- server/memphis_handlers_user_mgmt.go | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/db/db.go b/db/db.go index 2f9ff1349..fe33c70c8 100644 --- a/db/db.go +++ b/db/db.go @@ -5260,6 +5260,31 @@ func GetStationIdsFromDlsMsgs(tenantName string) ([]int, error) { return stationIds, nil } +func DeleteDlsMsgsByTenant(tenantName string) error { + ctx, cancelfunc := context.WithTimeout(context.Background(), DbOperationTimeout*time.Second) + defer cancelfunc() + + conn, err := MetadataDbClient.Client.Acquire(ctx) + if err != nil { + return err + } + defer conn.Release() + + removeUserQuery := `DELETE FROM dls_messages WHERE tenant_name = $1` + + stmt, err := conn.Conn().Prepare(ctx, "remove_dls_msgs_by_tenant", removeUserQuery) + if err != nil { + return err + } + _, err = conn.Conn().Exec(ctx, stmt.Name, tenantName) + if err != nil { + return err + } + + return nil + +} + // Tenants functions func UpsertTenant(name string) (models.Tenant, error) { ctx, cancelfunc := context.WithTimeout(context.Background(), DbOperationTimeout*time.Second) diff --git a/server/background_tasks.go b/server/background_tasks.go index efa206339..d20cd903c 100644 --- a/server/background_tasks.go +++ b/server/background_tasks.go @@ -266,7 +266,7 @@ func (s *Server) StartBackgroundTasks() error { return err } go s.UploadTenantUsageToDB() - go s.ConnectToFirebaseFunction() + go s.RefreshFirebaseFUnctionKey() return nil } diff --git a/server/memphis_cloud.go b/server/memphis_cloud.go index 0ca2f4332..21062652e 100644 --- a/server/memphis_cloud.go +++ b/server/memphis_cloud.go @@ -1418,13 +1418,6 @@ func (umh UserMgmtHandler) RemoveMyUser(c *gin.Context) { return } - err = db.DeleteUser(user.Username, user.TenantName) - if err != nil { - serv.Errorf("RemoveMyUser: User " + user.Username + ": " + err.Error()) - c.AbortWithStatusJSON(500, gin.H{"message": "Server error"}) - return - } - shouldSendAnalytics, _ := shouldSendAnalytics() if shouldSendAnalytics { analytics.SendEvent(user.Username, "user-remove-himself") @@ -1434,5 +1427,5 @@ func (umh UserMgmtHandler) RemoveMyUser(c *gin.Context) { c.IndentedJSON(200, gin.H{}) } -func (s *Server) ConnectToFirebaseFunction() { +func (s *Server) RefreshFirebaseFUnctionKey() { } diff --git a/server/memphis_handlers_user_mgmt.go b/server/memphis_handlers_user_mgmt.go index e223c8f69..4dcb73ca0 100644 --- a/server/memphis_handlers_user_mgmt.go +++ b/server/memphis_handlers_user_mgmt.go @@ -182,6 +182,21 @@ func removeTenantResources(tenantName string) error { return err } + err = db.DeleteUsersByTenant(tenantName) + if err != nil { + return err + } + + err = db.DeleteDlsMsgsByTenant(tenantName) + if err != nil { + return err + } + + err = db.RemoveTenant(tenantName) + if err != nil { + return err + } + for _, station := range stations { stationName := strings.ToLower(station.Name) sName, err := StationNameFromStr(stationName) From 253274bfada3d2a2e6eace1e89460a427a99b989 Mon Sep 17 00:00:00 2001 From: idanasulinStrech Date: Sat, 17 Jun 2023 14:04:21 +0300 Subject: [PATCH 2/2] typo --- server/background_tasks.go | 2 +- server/memphis_cloud.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/background_tasks.go b/server/background_tasks.go index d20cd903c..0c5fec75b 100644 --- a/server/background_tasks.go +++ b/server/background_tasks.go @@ -266,7 +266,7 @@ func (s *Server) StartBackgroundTasks() error { return err } go s.UploadTenantUsageToDB() - go s.RefreshFirebaseFUnctionKey() + go s.RefreshFirebaseFunctionsKey() return nil } diff --git a/server/memphis_cloud.go b/server/memphis_cloud.go index 21062652e..313991627 100644 --- a/server/memphis_cloud.go +++ b/server/memphis_cloud.go @@ -1427,5 +1427,5 @@ func (umh UserMgmtHandler) RemoveMyUser(c *gin.Context) { c.IndentedJSON(200, gin.H{}) } -func (s *Server) RefreshFirebaseFUnctionKey() { +func (s *Server) RefreshFirebaseFunctionsKey() { }