Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes for cloud #988

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/background_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (s *Server) StartBackgroundTasks() error {
return err
}
go s.UploadTenantUsageToDB()
go s.ConnectToFirebaseFunction()
go s.RefreshFirebaseFunctionsKey()
return nil
}

Expand Down
9 changes: 1 addition & 8 deletions server/memphis_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -1434,5 +1427,5 @@ func (umh UserMgmtHandler) RemoveMyUser(c *gin.Context) {
c.IndentedJSON(200, gin.H{})
}

func (s *Server) ConnectToFirebaseFunction() {
func (s *Server) RefreshFirebaseFunctionsKey() {
}
15 changes: 15 additions & 0 deletions server/memphis_handlers_user_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down