From 715f3092d8ab132eb2eb4f041d40aa02e8126532 Mon Sep 17 00:00:00 2001 From: yashsinghcodes Date: Thu, 21 Nov 2024 20:28:43 +0530 Subject: [PATCH 1/8] fixed same condition --- shared.go | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/shared.go b/shared.go index e9e1ee5..da237e8 100755 --- a/shared.go +++ b/shared.go @@ -17837,7 +17837,6 @@ func PrepareSingleAction(ctx context.Context, user User, fileId string, body []b } } - if runValidationAction { log.Printf("[INFO] Running validation action for %s for org %s (%s)", app.Name, user.ActiveOrg.Name, user.ActiveOrg.Id) @@ -24496,9 +24495,8 @@ func GetExternalClient(baseUrl string) *http.Client { } } - if (len(httpProxy) > 0 || len(httpsProxy) > 0) && baseUrl != "http://shuffle-backend:5001" { - //client = &http.Client{} - if len(httpProxy) > 0 && httpProxy != "noproxy" { + if (len(httpProxy) > 0 || len(httpsProxy) > 0) && (strings.ToLower(httpProxy) != "noproxy" || strings.ToLower(httpsProxy) != "noproxy") { + if len(httpProxy) > 0 && strings.ToLower(httpProxy) != "noproxy" { log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy) url_i := url.URL{} @@ -24507,27 +24505,8 @@ func GetExternalClient(baseUrl string) *http.Client { transport.Proxy = http.ProxyURL(url_proxy) } } - if len(httpsProxy) > 0 && httpsProxy != "noproxy" { - log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy) - - url_i := url.URL{} - url_proxy, err := url_i.Parse(httpsProxy) - if err == nil { - transport.Proxy = http.ProxyURL(url_proxy) - } - } - } else { - // keeping this here for now - if len(httpProxy) > 0 && httpProxy != "noproxy" { - log.Printf("[INFO] Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy) - url_i := url.URL{} - url_proxy, err := url_i.Parse(httpProxy) - if err == nil { - transport.Proxy = http.ProxyURL(url_proxy) - } - } - if len(httpsProxy) > 0 && httpsProxy != "noproxy" { + if len(httpsProxy) > 0 && strings.ToLower(httpsProxy) != "noproxy" { log.Printf("[INFO] Running with HTTPS proxy %s (env: HTTPS_PROXY)", httpsProxy) url_i := url.URL{} From 23134fdf3dc1cd8962d4336789610631a2cee842 Mon Sep 17 00:00:00 2001 From: yashsinghcodes Date: Sat, 30 Nov 2024 02:46:29 +0530 Subject: [PATCH 2/8] auto scale time window func --- shared.go | 47 +++++++++++++++++++++++++++++++++++++---------- structs.go | 17 ++++++++++++----- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/shared.go b/shared.go index 0ed5f18..60ad6c5 100755 --- a/shared.go +++ b/shared.go @@ -5674,20 +5674,20 @@ func SetNewWorkflow(resp http.ResponseWriter, request *http.Request) { AppVersion: app.AppVersion, AppID: app.ID, LargeImage: app.LargeImage, - } + } - newAction.Position = Position{ - X: 449.5, - Y: 446, + newAction.Position = Position{ + X: 449.5, + Y: 446, + } + + newActions = append(newActions, newAction) } - newActions = append(newActions, newAction) + } else { + // figure out a way to activate Shuffle-Tools-Fork for everyone onprem } - } else { - // figure out a way to activate Shuffle-Tools-Fork for everyone onprem - } - } else { for _, item := range workflowapps { //log.Printf("NAME: %s", item.Name) @@ -17886,7 +17886,6 @@ func PrepareSingleAction(ctx context.Context, user User, fileId string, body []b } } - if runValidationAction { log.Printf("[INFO] Running validation action for %s for org %s (%s)", app.Name, user.ActiveOrg.Name, user.ActiveOrg.Id) @@ -29881,3 +29880,31 @@ func SendDeleteWorkflowRequest(childWorkflow Workflow, request *http.Request) er return nil } + +func NewTimeWindow(duration time.Duration) *TimeWindow { + return &TimeWindow{ + Duration: duration, + Events: []time.Time{}, + } +} + +func (tw *TimeWindow) AddEvent(event time.Time) { + tw.mu.Lock() + defer tw.mu.Unlock() + tw.Events = append(tw.Events, event) + tw.cleanOldEvents(event) +} + +func (tw *TimeWindow) CountEvents(now time.Time) int { + tw.mu.Lock() + defer tw.mu.Unlock() + tw.cleanOldEvents(now) + return len(tw.Events) +} + +func (tw *TimeWindow) cleanOldEvents(now time.Time) { + cutoff := now.Add(-tw.Duration) + for len(tw.Events) > 0 && tw.Events[0].Before(cutoff) { + tw.Events = tw.Events[1:] + } +} diff --git a/structs.go b/structs.go index 3481a5f..3609391 100755 --- a/structs.go +++ b/structs.go @@ -2,6 +2,7 @@ package shuffle import ( "encoding/xml" + "sync" "time" ) @@ -24,7 +25,7 @@ type LogRequest struct { } type PipelineRequest struct { - ID string `json:"id"` + ID string `json:"id"` Name string `json:"name"` Type string `json:"type"` Command string `json:"command"` @@ -39,7 +40,7 @@ type PipelineRequest struct { type Pipeline struct { Name string `json:"name" datastore:"name"` - ID string `json:"id" datastore:"id"` + ID string `json:"id" datastore:"id"` Type string `json:"type" datastore:"type"` Command string `json:"command" datastore:"command"` Environment string `json:"environment" datastore:"environment"` @@ -1263,14 +1264,14 @@ type InputQuestion struct { } type FormControl struct { - InputMarkdown string `json:"input_markdown" datastore:"input_markdown,noindex"` - OutputYields []string `json:"output_yields" datastore:"output_yields"` // Defines the nodes that will YIELD their output to the frontend during execution + InputMarkdown string `json:"input_markdown" datastore:"input_markdown,noindex"` + OutputYields []string `json:"output_yields" datastore:"output_yields"` // Defines the nodes that will YIELD their output to the frontend during execution FormWidth int64 `json:"form_width" datastore:"form_width"` } type Workflow struct { - WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"` + WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"` Actions []Action `json:"actions" datastore:"actions,noindex"` Branches []Branch `json:"branches" datastore:"branches,noindex"` VisualBranches []Branch `json:"visual_branches" datastore:"visual_branches,noindex"` @@ -4169,3 +4170,9 @@ type RequestResponse struct { Reason string `json:"reason"` Details string `json:"details"` } + +type TimeWindow struct { + Duration time.Duration + Events []time.Time + mu sync.Mutex +} From 092c297582de276d73b1e80d7bee69d4234ca308 Mon Sep 17 00:00:00 2001 From: lalitdeore Date: Mon, 2 Dec 2024 18:47:15 +0530 Subject: [PATCH 3/8] fix autoprovisining of users --- shared.go | 20 ++++++++++++++++++++ structs.go | 1 + 2 files changed, 21 insertions(+) diff --git a/shared.go b/shared.go index 0ed5f18..ba614e2 100755 --- a/shared.go +++ b/shared.go @@ -11746,6 +11746,10 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) { org.SSOConfig = tmpData.SSOConfig } + if tmpData.SSOConfig.AutoProvision != org.SSOConfig.AutoProvision { + org.SSOConfig.AutoProvision = tmpData.SSOConfig.AutoProvision + } + if (tmpData.SSOConfig.OpenIdClientId != org.SSOConfig.OpenIdClientId) || (tmpData.SSOConfig.OpenIdAuthorization != org.SSOConfig.OpenIdAuthorization) { org.SSOConfig = tmpData.SSOConfig } @@ -19268,6 +19272,14 @@ func HandleOpenId(resp http.ResponseWriter, request *http.Request) { return } + //Don't create user if auto-provisioning is disabled + if org.SSOConfig.AutoProvision { + log.Printf("[INFO] Auto-provisioning is disable for id: %s", org.Id) + resp.WriteHeader(401) + resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Auto-provisioning is disabled for this organization. Please ask your administrator to enable it."}`))) + return + } + log.Printf("[AUDIT] Adding user %s to org %s (%s) through single sign-on", userName, org.Name, org.Id) newUser := new(User) // Random password to ensure its not empty @@ -19797,6 +19809,14 @@ func HandleSSO(resp http.ResponseWriter, request *http.Request) { return } + //Don't create user if auto-provisioning is disabled + if foundOrg.SSOConfig.AutoProvision { + log.Printf("[INFO] Auto-provisioning is disable for id: %s", foundOrg.Id) + resp.WriteHeader(401) + resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Auto-provisioning is disabled for this organization. Please ask your administrator to enable it."}`))) + return + } + log.Printf("[AUDIT] Adding user %s to org %s (%s) through single sign-on", userName, foundOrg.Name, foundOrg.Id) newUser := new(User) // Random password to ensure its not empty diff --git a/structs.go b/structs.go index 3481a5f..8396dcb 100755 --- a/structs.go +++ b/structs.go @@ -2737,6 +2737,7 @@ type SSOConfig struct { OpenIdAuthorization string `json:"openid_authorization" datastore:"openid_authorization"` OpenIdToken string `json:"openid_token" datastore:"openid_token"` SSORequired bool `json:"SSORequired" datastore:"SSORequired"` + AutoProvision bool `json:"auto_provision" datastore:"auto_provision"` } type SamlRequest struct { From d0f6b61044aa1b926ac58223e08df80ec6dfd7a6 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:55:57 +0530 Subject: [PATCH 4/8] fix: Webhooks distributed at the parent level to suborgs are not dynamically generating a different UUID as the parent --- shared.go | 171 +++++++++++++++++++++++++++++------------------------- 1 file changed, 92 insertions(+), 79 deletions(-) diff --git a/shared.go b/shared.go index 87c60b7..546cb4f 100755 --- a/shared.go +++ b/shared.go @@ -6429,17 +6429,17 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } // Create / Delete / Modify - //log.Printf("\n ===== Parent: %#v, Child: %#v =====", parentWorkflow.ID, oldWorkflow.ID) - //log.Printf("\n Changes: c | d | m\n Action: %d | %d | %d\n Trigger: %d | %d | %d\n Branch: %d | %d | %d", len(addedActions), len(removedActions), len(updatedActions), len(addedTriggers), len(removedTriggers), len(updatedTriggers), len(addedBranches), len(removedBranches), len(updatedBranches)) + log.Printf("\n ===== Parent: %#v, Child: %#v =====", parentWorkflow.ID, oldWorkflow.ID) + log.Printf("\n Changes: c | d | m\n Action: %d | %d | %d\n Trigger: %d | %d | %d\n Branch: %d | %d | %d", len(addedActions), len(removedActions), len(updatedActions), len(addedTriggers), len(removedTriggers), len(updatedTriggers), len(addedBranches), len(removedBranches), len(updatedBranches)) if update { // FIXME: This doesn't work does it? childWorkflow := oldWorkflow - //log.Printf("\n\nSTART") - //log.Printf("[DEBUG] CHILD ACTIONS START: %d", len(childWorkflow.Actions)) - //log.Printf("[DEBUG] CHILD TRIGGERS START: %d", len(childWorkflow.Triggers)) - //log.Printf("[DEBUG] CHILD BRANCHES START: %d\n\n", len(childWorkflow.Branches)) + log.Printf("\n\nSTART") + log.Printf("[DEBUG] CHILD ACTIONS START: %d", len(childWorkflow.Actions)) + log.Printf("[DEBUG] CHILD TRIGGERS START: %d", len(childWorkflow.Triggers)) + log.Printf("[DEBUG] CHILD BRANCHES START: %d\n\n", len(childWorkflow.Branches)) if nameChanged { childWorkflow.Name = parentWorkflow.Name @@ -6698,68 +6698,66 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { // FIXME: Add specific handlers for each type based on oldWorkflow params that may have been locally configured // FIXME: THIS DOES NOT WORK YET FOR TRIGGER FIELD MAPPING TO OLD SETTING if childTrigger.ParentControlled { - /* - for _, oldTrigger := range oldWorkflow.Triggers { - if oldTrigger.ID != childTrigger.ID { - continue - } - - childTrigger.Status = oldTrigger.Status - - reservedArguments := []string{} - if oldTrigger.TriggerType == "SUBFLOW" { - reservedArguments = []string{"workflow", "user_apikey", "startnode"} - } else if oldTrigger.TriggerType == "USERINPUT" { - reservedArguments = []string{"subflow", "sms", "email", "type"} - } else if oldTrigger.TriggerType == "SCHEDULE" { - } else if oldTrigger.TriggerType == "WEBHOOK" { - reservedArguments = []string{"url", "tmp", "auth_headers"} - } else if oldTrigger.TriggerType == "PIPELINE" { - reservedArguments = []string{"pipeline"} - } - - fieldsFound := []string{} - for paramIndex, param := range childTrigger.Parameters { - if !ArrayContains(reservedArguments, param.Name) { - continue - } - - fieldsFound = append(fieldsFound, param.Name) - for _, oldParam := range oldTrigger.Parameters { - if oldParam.Name != param.Name { - continue - } - - childWorkflow.Triggers[childTriggerIndex].Parameters[paramIndex].Value = oldParam.Value - childTrigger.Parameters[paramIndex].Value = oldParam.Value - break - } - } - - if len(fieldsFound) != len(reservedArguments) { - for _, field := range reservedArguments { - if ArrayContains(fieldsFound, field) { - continue - } - - oldParamFound := false - for _, oldParam := range oldTrigger.Parameters { - if oldParam.Name != field { - continue - } - - oldParamFound = true - childTrigger.Parameters = append(childTrigger.Parameters, oldParam) - childWorkflow.Triggers[childTriggerIndex].Parameters = append(childWorkflow.Triggers[childTriggerIndex].Parameters, oldParam) - } - - if !oldParamFound { - //log.Printf("[DEBUG] MISSING IN OLDPARAM TOO: %s", field) - } - } - } - } - */ + // for _, oldTrigger := range oldWorkflow.Triggers { + // if oldTrigger.ID != childTrigger.ID { + // continue + // } + + // childTrigger.Status = oldTrigger.Status + + // reservedArguments := []string{} + // if oldTrigger.TriggerType == "SUBFLOW" { + // reservedArguments = []string{"workflow", "user_apikey", "startnode"} + // } else if oldTrigger.TriggerType == "USERINPUT" { + // reservedArguments = []string{"subflow", "sms", "email", "type"} + // } else if oldTrigger.TriggerType == "SCHEDULE" { + // } else if oldTrigger.TriggerType == "WEBHOOK" { + // reservedArguments = []string{"url", "tmp", "auth_headers"} + // } else if oldTrigger.TriggerType == "PIPELINE" { + // reservedArguments = []string{"pipeline"} + // } + + // fieldsFound := []string{} + // for paramIndex, param := range childTrigger.Parameters { + // if !ArrayContains(reservedArguments, param.Name) { + // continue + // } + + // fieldsFound = append(fieldsFound, param.Name) + // for _, oldParam := range oldTrigger.Parameters { + // if oldParam.Name != param.Name { + // continue + // } + + // childWorkflow.Triggers[childTriggerIndex].Parameters[paramIndex].Value = oldParam.Value + // childTrigger.Parameters[paramIndex].Value = oldParam.Value + // break + // } + // } + + // if len(fieldsFound) != len(reservedArguments) { + // for _, field := range reservedArguments { + // if ArrayContains(fieldsFound, field) { + // continue + // } + + // oldParamFound := false + // for _, oldParam := range oldTrigger.Parameters { + // if oldParam.Name != field { + // continue + // } + + // oldParamFound = true + // childTrigger.Parameters = append(childTrigger.Parameters, oldParam) + // childWorkflow.Triggers[childTriggerIndex].Parameters = append(childWorkflow.Triggers[childTriggerIndex].Parameters, oldParam) + // } + + // if !oldParamFound { + // //log.Printf("[DEBUG] MISSING IN OLDPARAM TOO: %s", field) + // } + // } + // } + // } } found := false @@ -6797,6 +6795,23 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } } + // print newTrigger params with old ones + for _, childTrigger := range childWorkflow.Triggers { + log.Printf("[DEBUG] Trigger %s (%s) has %d parameters", childTrigger.Label, childTrigger.ID, len(childTrigger.Parameters)) + for _, param := range childTrigger.Parameters { + log.Printf("%+v", childTrigger.Parameters) + log.Printf("[DEBUG] Trigger %s (%s) param %s: %s", childTrigger.Label, childTrigger.ID, param.Name, param.Value) + } + } + + for _, newTrigger := range newTriggers { + log.Printf("[DEBUG] New Trigger %s (%s) has %d parameters", newTrigger.Label, newTrigger.ID, len(newTrigger.Parameters)) + for _, param := range newTrigger.Parameters { + log.Printf("%+v", newTrigger.Parameters) + log.Printf("[DEBUG] New Trigger %s (%s) param %s: %s", newTrigger.Label, newTrigger.ID, param.Name, param.Value) + } + } + childWorkflow.Actions = newActions childWorkflow.Triggers = newTriggers childWorkflow.Branches = newBranches @@ -9640,32 +9655,30 @@ func GenerateWorkflowFromParent(ctx context.Context, workflow Workflow, parentOr } } - for actionIndex, _ := range workflow.Actions { + for actionIndex, _ := range newWf.Actions { workflow.Actions[actionIndex].ParentControlled = true workflow.Actions[actionIndex].AuthenticationId = "" workflow.Actions[actionIndex].Environment = defaultEnvironment } - for triggerIndex, _ := range workflow.Triggers { - workflow.Triggers[triggerIndex].ParentControlled = true - workflow.Triggers[triggerIndex].Environment = defaultEnvironment + for triggerIndex, _ := range newWf.Triggers { + newWf.Triggers[triggerIndex].ParentControlled = true + newWf.Triggers[triggerIndex].Environment = defaultEnvironment // FIXME: How do we manage secondary IDs? // E.g. for webhooks, how do we have a URL correctly, and start/stop properly? - - workflow.Triggers[triggerIndex].Status = "uninitialized" - if workflow.Triggers[triggerIndex].TriggerType == "WEBHOOK" { - for paramIndex, param := range workflow.Triggers[triggerIndex].Parameters { + newWf.Triggers[triggerIndex].Status = "uninitialized" + if newWf.Triggers[triggerIndex].TriggerType == "WEBHOOK" { + for paramIndex, param := range newWf.Triggers[triggerIndex].Parameters { if param.Name == "url" { - workflow.Triggers[triggerIndex].Parameters[paramIndex].Value = "" + newWf.Triggers[triggerIndex].Parameters[paramIndex].Value = "" } if param.Name == "tmp" { - workflow.Triggers[triggerIndex].Parameters[paramIndex].Value = "" + newWf.Triggers[triggerIndex].Parameters[paramIndex].Value = "" } } } - } err = SetWorkflow(ctx, newWf, newWf.ID) From 7453c5206d1458e22fbaed39e9d512bd3d46744a Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:57:16 +0530 Subject: [PATCH 5/8] fix: Removing unnecessary printing --- shared.go | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/shared.go b/shared.go index 546cb4f..9711392 100755 --- a/shared.go +++ b/shared.go @@ -6429,17 +6429,17 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } // Create / Delete / Modify - log.Printf("\n ===== Parent: %#v, Child: %#v =====", parentWorkflow.ID, oldWorkflow.ID) - log.Printf("\n Changes: c | d | m\n Action: %d | %d | %d\n Trigger: %d | %d | %d\n Branch: %d | %d | %d", len(addedActions), len(removedActions), len(updatedActions), len(addedTriggers), len(removedTriggers), len(updatedTriggers), len(addedBranches), len(removedBranches), len(updatedBranches)) + // log.Printf("\n ===== Parent: %#v, Child: %#v =====", parentWorkflow.ID, oldWorkflow.ID) + // log.Printf("\n Changes: c | d | m\n Action: %d | %d | %d\n Trigger: %d | %d | %d\n Branch: %d | %d | %d", len(addedActions), len(removedActions), len(updatedActions), len(addedTriggers), len(removedTriggers), len(updatedTriggers), len(addedBranches), len(removedBranches), len(updatedBranches)) if update { // FIXME: This doesn't work does it? childWorkflow := oldWorkflow - log.Printf("\n\nSTART") - log.Printf("[DEBUG] CHILD ACTIONS START: %d", len(childWorkflow.Actions)) - log.Printf("[DEBUG] CHILD TRIGGERS START: %d", len(childWorkflow.Triggers)) - log.Printf("[DEBUG] CHILD BRANCHES START: %d\n\n", len(childWorkflow.Branches)) + // log.Printf("\n\nSTART") + // log.Printf("[DEBUG] CHILD ACTIONS START: %d", len(childWorkflow.Actions)) + // log.Printf("[DEBUG] CHILD TRIGGERS START: %d", len(childWorkflow.Triggers)) + // log.Printf("[DEBUG] CHILD BRANCHES START: %d\n\n", len(childWorkflow.Branches)) if nameChanged { childWorkflow.Name = parentWorkflow.Name @@ -6795,23 +6795,6 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } } - // print newTrigger params with old ones - for _, childTrigger := range childWorkflow.Triggers { - log.Printf("[DEBUG] Trigger %s (%s) has %d parameters", childTrigger.Label, childTrigger.ID, len(childTrigger.Parameters)) - for _, param := range childTrigger.Parameters { - log.Printf("%+v", childTrigger.Parameters) - log.Printf("[DEBUG] Trigger %s (%s) param %s: %s", childTrigger.Label, childTrigger.ID, param.Name, param.Value) - } - } - - for _, newTrigger := range newTriggers { - log.Printf("[DEBUG] New Trigger %s (%s) has %d parameters", newTrigger.Label, newTrigger.ID, len(newTrigger.Parameters)) - for _, param := range newTrigger.Parameters { - log.Printf("%+v", newTrigger.Parameters) - log.Printf("[DEBUG] New Trigger %s (%s) param %s: %s", newTrigger.Label, newTrigger.ID, param.Name, param.Value) - } - } - childWorkflow.Actions = newActions childWorkflow.Triggers = newTriggers childWorkflow.Branches = newBranches From 65bf4ee412f3d17464fa55a37cd8cb920c1517c1 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:21:22 +0530 Subject: [PATCH 6/8] fix: updates for lalit --- shared.go | 40 ++++++++++++++++++++++++++++++++++++++++ structs.go | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/shared.go b/shared.go index 9711392..b5fd353 100755 --- a/shared.go +++ b/shared.go @@ -6554,13 +6554,20 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } } + + for _, trigger := range childWorkflow.Triggers { + + if len(addedTriggers) > 0 { + log.Printf("[DEBUG] Triggers added: %d", len(addedTriggers)) triggers := childTriggers for _, trigger := range parentWorkflow.Triggers { if !ArrayContains(addedTriggers, trigger.ID) { continue } + log.Printf("[DEBUG] ID of the added trigger: %s", trigger.ID) + triggers = append(triggers, trigger) } @@ -6583,7 +6590,9 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } if len(updatedTriggers) > 0 { + log.Printf("[DEBUG] Triggers updated: %d", len(updatedTriggers)) for _, action := range updatedTriggers { + log.Printf("[DEBUG] ID of the updated trigger: %s", action.ID) for index, childAction := range childWorkflow.Triggers { if childAction.ID != action.ID { continue @@ -6795,6 +6804,22 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } } + // Old childWorkflow triggers: + for _, oldTrigger := range oldWorkflow.Triggers { + // params + for _, param := range oldTrigger.Parameters { + log.Printf("[DEBUG] Old trigger %s (%s) has param %s and value: %s", oldTrigger.Label, oldTrigger.ID, param.Name, param.Value) + } + } + + // to be updated triggers + for _, trigger := range newTriggers { + // params + for _, param := range trigger.Parameters { + log.Printf("[DEBUG] New trigger %s (%s) has param %s and value: %s", trigger.Label, trigger.ID, param.Name, param.Value) + } + } + childWorkflow.Actions = newActions childWorkflow.Triggers = newTriggers childWorkflow.Branches = newBranches @@ -9652,6 +9677,8 @@ func GenerateWorkflowFromParent(ctx context.Context, workflow Workflow, parentOr // E.g. for webhooks, how do we have a URL correctly, and start/stop properly? newWf.Triggers[triggerIndex].Status = "uninitialized" if newWf.Triggers[triggerIndex].TriggerType == "WEBHOOK" { + oldID := newWf.Triggers[triggerIndex].ID + newWf.Triggers[triggerIndex].ID = uuid.NewV4().String() for paramIndex, param := range newWf.Triggers[triggerIndex].Parameters { if param.Name == "url" { newWf.Triggers[triggerIndex].Parameters[paramIndex].Value = "" @@ -9660,6 +9687,19 @@ func GenerateWorkflowFromParent(ctx context.Context, workflow Workflow, parentOr if param.Name == "tmp" { newWf.Triggers[triggerIndex].Parameters[paramIndex].Value = "" } + + newWf.Triggers[triggerIndex].ReplacementForTrigger = oldID + + // edit all branch source ids where the ID is changed + for branchIndex, branch := range newWf.Branches { + if branch.SourceID == oldID { + newWf.Branches[branchIndex].SourceID = newWf.Triggers[triggerIndex].ID + } + + if branch.DestinationID == oldID { + newWf.Branches[branchIndex].DestinationID = newWf.Triggers[triggerIndex].ID + } + } } } } diff --git a/structs.go b/structs.go index 3609391..54c585b 100755 --- a/structs.go +++ b/structs.go @@ -1206,8 +1206,9 @@ type Trigger struct { SourceWorkflow string `json:"source_workflow" yaml:"source_workflow" datastore:"source_workflow"` ExecutionDelay int64 `json:"execution_delay" yaml:"execution_delay" datastore:"execution_delay"` AppAssociation WorkflowApp `json:"app_association" yaml:"app_association" datastore:"app_association"` - ParentControlled bool `json:"parent_controlled" datastore:"parent_controlled"` // If the parent workflow node exists, and shouldn't be editable by child workflow + + ReplacementForTrigger string `json:"replacement_for_trigger" datastore:"replacement_for_trigger"` // If this trigger is a replacement for another trigger } type Branch struct { From cd87dd9e73a7265e3a9d55547a771683e08585b3 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:41:28 +0530 Subject: [PATCH 7/8] fix: Hook issue replication issue in distributed workflows --- shared.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/shared.go b/shared.go index b5fd353..478a937 100755 --- a/shared.go +++ b/shared.go @@ -6554,19 +6554,25 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) { } } - - for _, trigger := range childWorkflow.Triggers { - + replacedTriggers := []string{} + for _, trigger := range oldWorkflow.Triggers { + if len(trigger.ReplacementForTrigger) > 0 { + replacedTriggers = append(replacedTriggers, trigger.ReplacementForTrigger) + } + } if len(addedTriggers) > 0 { - log.Printf("[DEBUG] Triggers added: %d", len(addedTriggers)) triggers := childTriggers for _, trigger := range parentWorkflow.Triggers { if !ArrayContains(addedTriggers, trigger.ID) { continue } - log.Printf("[DEBUG] ID of the added trigger: %s", trigger.ID) + if ArrayContains(replacedTriggers, trigger.ID) { + continue + } + + // log.Printf("[DEBUG] ID of the added trigger: %s", trigger.ID) triggers = append(triggers, trigger) } From 15ad3b3ce98af480c50aab277d32d92967b63620 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:59:02 +0530 Subject: [PATCH 8/8] fix: schedule trigger not starting for distributed workflows --- shared.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shared.go b/shared.go index 478a937..efbe9b4 100755 --- a/shared.go +++ b/shared.go @@ -9707,6 +9707,22 @@ func GenerateWorkflowFromParent(ctx context.Context, workflow Workflow, parentOr } } } + } else if newWf.Triggers[triggerIndex].TriggerType == "SCHEDULE" { + oldID := newWf.Triggers[triggerIndex].ID + newWf.Triggers[triggerIndex].ID = uuid.NewV4().String() + + newWf.Triggers[triggerIndex].ReplacementForTrigger = oldID + + + for branchIndex, branch := range newWf.Branches { + if branch.SourceID == oldID { + newWf.Branches[branchIndex].SourceID = newWf.Triggers[triggerIndex].ID + } + + if branch.DestinationID == oldID { + newWf.Branches[branchIndex].DestinationID = newWf.Triggers[triggerIndex].ID + } + } } }