Skip to content

Commit

Permalink
Fixed usecase mapping to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Aug 8, 2024
1 parent 139ddc5 commit 6260c3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11968,7 +11968,8 @@ func GetUsecase(ctx context.Context, name string) (*Usecase, error) {
log.Printf("[INFO] Error in usecase loading. Migrating usecase to new workflow handler.")
err = nil
} else {
return usecase, err
// Let it cache. No point in DB searching every time
//return usecase, err
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -11314,8 +11314,6 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {

SyncFeatures SyncFeatures `json:"sync_features" datastore:"sync_features"`
Billing Billing `json:"billing" datastore:"billing"`

UsecaseAttempt string `json:"usecase_attempt" datastore:"usecase_attempt"`
}

var tmpData ReturnData
Expand Down Expand Up @@ -22271,7 +22269,7 @@ func HandleGetUsecase(resp http.ResponseWriter, request *http.Request) {
return
}

_, err := HandleApiAuthentication(resp, request)
user, err := HandleApiAuthentication(resp, request)
if err != nil {
log.Printf("[WARNING] Api authentication failed in get usecase (1). Continuing anyway: %s", err)
//resp.WriteHeader(401)
Expand Down Expand Up @@ -22306,6 +22304,33 @@ func HandleGetUsecase(resp http.ResponseWriter, request *http.Request) {
usecase.Success = true
}

if len(user.ActiveOrg.Id) > 0 && usecase.Name != "Reporting" && len(usecase.Name) > 3 {
org, err := GetOrg(ctx, user.ActiveOrg.Id)
if err == nil && len(org.Id) > 0 {
found := false
for _, interest := range org.Interests {
if interest.Name != usecase.Name {
continue
}

found = true
break
}

if !found {
log.Printf("[DEBUG] Updating org %s with usecase %s as interesting", user.ActiveOrg.Id, usecase.Name)
org.Interests = append(org.Interests, Priority{
Name : usecase.Name,
Description: fmt.Sprintf("User %s (%s) has shown interest in this usecase", user.Username, user.Id),
Type : "usecase",
Active : true,
})

SetOrg(ctx, *org, org.Id)
}
}
}

// Hardcoding until we have something good for open source + cloud
replacedName := strings.Replace(strings.ToLower(usecase.Name), " ", "_", -1)
if replacedName == "email_management" {
Expand Down
5 changes: 4 additions & 1 deletion structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,17 @@ type Org struct {
PartnerInfo PartnerInfo `json:"partner_info" datastore:"partner_info"`
SSOConfig SSOConfig `json:"sso_config" datastore:"sso_config"`
SecurityFramework Categories `json:"security_framework" datastore:"security_framework,noindex"`

Interests []Priority `json:"interests" datastore:"interests"`
Priorities []Priority `json:"priorities" datastore:"priorities,noindex"`
MainPriority string `json:"main_priority" datastore:"main_priority"`

Region string `json:"region" datastore:"region"`
RegionUrl string `json:"region_url" datastore:"region_url"`
Tutorials []Tutorial `json:"tutorials" datastore:"tutorials"`
LeadInfo LeadInfo `json:"lead_info,omitempty" datastore:"lead_info"`
OrgAuth OrgAuth `json:"org_auth" datastore:"org_auth"`


CreatorId string `json:"creator_id" datastore:"creator_id"`
Disabled bool `json:"disabled" datastore:"disabled"`

Expand Down Expand Up @@ -2600,6 +2602,7 @@ type HandleInfo struct {
ActiveOrg OrgMini `json:"active_org"`
EthInfo EthInfo `json:"eth_info,omitempty"`
ChatDisabled bool `json:"chat_disabled"`
Interests []Priority `json:"interests"`
Priorities []Priority `json:"priorities"`
Cookies []SessionCookie `json:"cookies"`
AppExecutionsLimit int64 `json:"app_execution_limit"`
Expand Down

0 comments on commit 6260c3c

Please sign in to comment.