Skip to content

Commit

Permalink
Added automatic subscription mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Frikky authored and Frikky committed Jul 25, 2023
1 parent 35c3f97 commit 71461bc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app_upload/stitcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,8 @@ func main() {
bucketName = os.Args[5]
}

appname := "shuffle-subflow"
appversion := "1.0.0"
appname := "email"
appversion := "1.3.0"
err := deployConfigToBackend(appfolder, appname, appversion)
if err != nil {
log.Printf("[WARNING] Failed uploading config: %s", err)
Expand Down
61 changes: 52 additions & 9 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,33 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {
//log.Printf("Envs: %s", len(envs))
org.SyncFeatures.MultiEnv.Usage = int64(len(envs))
}

if len(org.Subscriptions) == 0 && project.Environment == "cloud" {
if org.LeadInfo.Customer || org.LeadInfo.POV || len(org.ManagerOrgs) > 0 {
name := "App execution units - default"
if len(org.ManagerOrgs) > 0 {
name = "Suborg access - default"
}

org.Subscriptions = append(org.Subscriptions, PaymentSubscription{
Active: true,
Startdate: int64(time.Now().Unix()),
CancellationDate: 0,
Enddate: 0,
Name: name,
Recurrence: string("monthly"),
Amount: string(rune(100000)),
Currency: string("USD"),
Level: "1",
Reference: "TBD",
Limit: 100000,
Features: []string{
"Custom Contract features",
"Multi-Tenant & Multi-Region",
},
})
}
}
}

// Make sure to add all orgs that are childs if you have access
Expand Down Expand Up @@ -1068,10 +1095,15 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {

}

if len(org.ManagerOrgs) > 0 {
org.LeadInfo.SubOrg = true
}

if !user.SupportAccess {
org.LeadInfo = LeadInfo{}
}


newjson, err := json.Marshal(org)
if err != nil {
log.Printf("[ERROR] Failed unmarshal of org %s (%s): %s", org.Name, org.Id, err)
Expand Down Expand Up @@ -7226,6 +7258,8 @@ func HandleChangeUserOrg(resp http.ResponseWriter, request *http.Request) {
DeleteCache(ctx, fmt.Sprintf("apps_%s", user.Id))
DeleteCache(ctx, fmt.Sprintf("user_%s", user.Username))
DeleteCache(ctx, fmt.Sprintf("user_%s", user.Id))
DeleteCache(ctx, fmt.Sprintf(user.ApiKey))
DeleteCache(ctx, fmt.Sprintf("session_%s", user.Session))

log.Printf("[DEBUG] Redirecting ORGCHANGE request to main site handler (shuffler.io)")
RedirectUserRequest(resp, request)
Expand All @@ -7235,6 +7269,7 @@ func HandleChangeUserOrg(resp http.ResponseWriter, request *http.Request) {
DeleteCache(ctx, fmt.Sprintf("user_%s", user.Username))
DeleteCache(ctx, fmt.Sprintf("user_%s", user.Id))
DeleteCache(ctx, fmt.Sprintf(user.ApiKey))
DeleteCache(ctx, fmt.Sprintf("session_%s", user.Session))

return
}
Expand Down Expand Up @@ -7806,36 +7841,40 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
if len(tmpData.LeadInfo) > 0 && user.SupportAccess {
log.Printf("[INFO] Updating lead info for %s to %s", org.Id, tmpData.LeadInfo)

// Make a new one, as to start with all from false
newLeadinfo := LeadInfo{}

for _, lead := range tmpData.LeadInfo {
if lead == "contacted" {
org.LeadInfo.Contacted = true
}
newLeadinfo.Contacted = true
}

if lead == "student" {
org.LeadInfo.Student = true
newLeadinfo.Student = true
}

if lead == "lead" {
org.LeadInfo.Lead = true
newLeadinfo.Lead = true
}

if lead == "pov" {
org.LeadInfo.POV = true
newLeadinfo.POV = true
}

if lead == "demo started" {
org.LeadInfo.DemoDone = true
newLeadinfo.DemoDone = true
}

if lead == "customer" {
org.LeadInfo.Customer = true
newLeadinfo.Customer = true
}

if lead == "internal" {
org.LeadInfo.Internal = true
newLeadinfo.Internal = true
}
}

org.LeadInfo = newLeadinfo
}

// Built a system around this now, which checks for the actual org.
Expand Down Expand Up @@ -9912,6 +9951,10 @@ func ParsedExecutionResult(ctx context.Context, workflowExecution WorkflowExecut

return &workflowExecution, true, nil
} else {
// Should NOT run with all this if the action is SKIPPED
// Cache when SKIPPED!


for _, param := range actionResult.Action.Parameters {
if param.Name == "check_result" {
//log.Printf("[INFO] RESULT: %s", param)
Expand Down Expand Up @@ -15873,7 +15916,7 @@ func SetFrameworkConfiguration(resp http.ResponseWriter, request *http.Request)
}

value.Type = strings.ToLower(value.Type)
if value.Type == "email" {
if value.Type == "email" || value.Type == "comms" {
value.Type = "communication"
}

Expand Down
8 changes: 6 additions & 2 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ type LeadInfo struct {
DemoDone bool `json:"demo_done,omitempty" datastore:"demo_done"`
Customer bool `json:"customer,omitempty" datastore:"customer"`
Internal bool `json:"internal,omitempty" datastore:"internal"`
SubOrg bool `json:"sub_org,omitempty" datastore:"sub_org"`
}

type Org struct {
Expand Down Expand Up @@ -799,6 +800,8 @@ type PaymentSubscription struct {
Level string `json:"level" datastore:"level"`
Amount string `json:"amount" datastore:"amount"`
Currency string `json:"currency" datastore:"currency"`
Limit int64 `json:"limit" datastore:"limit"`
Features []string `json:"features" datastore:"features"`
}

type SyncUsage struct {
Expand Down Expand Up @@ -2176,15 +2179,16 @@ type HandleInfo struct {
Avatar string `json:"avatar"`
Orgs []OrgMini `json:"orgs"`
ActiveOrg OrgMini `json:"active_org"`
EthInfo EthInfo `json:"eth_info"`
EthInfo EthInfo `json:"eth_info,omitempty"`
ChatDisabled bool `json:"chat_disabled"`
Priorities []Priority `json:"priorities"`
Cookies []SessionCookie `json:"cookies"`
AppExecutionsLimit int64 `json:"app_execution_limit"`
AppExecutionsUsage int64 `json:"app_execution_usage"`
RegionUrl string `json:"region_url"`
Tutorials []Tutorial `json:"tutorials"`
Support bool `json:"support"`
Tutorials []Tutorial `json:"tutorials"`
OrgStatus []string `json:"org_status"`
}

//Cookies []SessionCookie `json:"session_cookie"`
Expand Down

0 comments on commit 71461bc

Please sign in to comment.