Skip to content

Commit

Permalink
Fixed a bug where users are null becuase of webhook update. Only happ…
Browse files Browse the repository at this point in the history
…ens in customer/pov tracking webhook
  • Loading branch information
frikky committed Sep 18, 2024
1 parent def7eda commit e7cc655
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4265,6 +4265,10 @@ func SetOrg(ctx context.Context, data Org, id string) error {
return errors.New(fmt.Sprintf("No ID provided for org %s", data.Name))
}

if len(data.Users) == 0 {
return errors.New("Not allowed to update an org without any users in the organization. Add at least one user to update")
}

if id != data.Id && len(data.Id) > 0 {
log.Printf("[ERROR] Org ID mismatch: %s != %s. Resetting ID", id, data.Id)
id = data.Id
Expand Down
35 changes: 18 additions & 17 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -11582,27 +11582,28 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
}

org.LeadInfo = newLeadinfo
//if org.LeadInfo != newLeadinfo {
log.Printf("[DEBUG] Lead info updated for %s (%s) from %#v to %#v", org.Id, org.Name, org.LeadInfo, newLeadinfo)

// Check for ORG_CHANGE_WEBHOOK
orgWebhook := os.Getenv("ORG_CHANGE_WEBHOOK")
if orgWebhook != "" && strings.HasPrefix(orgWebhook, "http") {
org.Users = []User{}
org.Subscriptions = []PaymentSubscription{}
org.Image = ""
org.ActiveApps = []string{}
org.SyncUsage = SyncUsage{}
org.SSOConfig = SSOConfig{}
org.SecurityFramework = Categories{}
// Make a copy of org to be modified without modifying the original
tmpOrg := *org

org.Priorities = []Priority{}
org.Interests = []Priority{}
tmpOrg.Users = []User{}
tmpOrg.Subscriptions = []PaymentSubscription{}
tmpOrg.Image = ""
tmpOrg.ActiveApps = []string{}
tmpOrg.SyncUsage = SyncUsage{}
tmpOrg.SSOConfig = SSOConfig{}
tmpOrg.SecurityFramework = Categories{}

org.OrgAuth = OrgAuth{}
org.Billing = Billing{}
tmpOrg.Priorities = []Priority{}
tmpOrg.Interests = []Priority{}

mappedData, err := json.Marshal(org)
tmpOrg.OrgAuth = OrgAuth{}
tmpOrg.Billing = Billing{}

mappedData, err := json.Marshal(tmpOrg)
if err != nil {
log.Printf("[WARNING] Marshal error for org sending: %s", err)
} else {
Expand All @@ -11627,7 +11628,6 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
defer res.Body.Close()
}
}

}

if len(tmpData.CreatorConfig) > 0 {
Expand Down Expand Up @@ -11750,10 +11750,11 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
// SSOUrl = org.SSOConfig.SSOEntrypoint
//}

//log.Printf("Org: %s", org)

log.Printf("[DEBUG] Updating org %s (%s) with %d users", org.Name, org.Id, len(org.Users))
err = SetOrg(ctx, *org, org.Id)
if err != nil {
log.Printf("[WARNING] Failed to edit org %s: %s", org.Id, err)
log.Printf("[ERROR] Failed to edit org %s: %s", org.Id, err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
Expand Down

0 comments on commit e7cc655

Please sign in to comment.