From 54b3687eefd9dff4f7753c8daccb857b6e78f620 Mon Sep 17 00:00:00 2001 From: Frikky Date: Tue, 19 Mar 2024 23:56:16 +0100 Subject: [PATCH] Fixed further user input issues --- backend/app_sdk/app_base.py | 11 +++- frontend/src/components/CacheView.jsx | 4 +- frontend/src/components/Files.jsx | 2 +- frontend/src/views/Admin.jsx | 23 ++++--- frontend/src/views/AngularWorkflow.jsx | 85 +++++++++++++++++++++++++- frontend/src/views/Workflows.jsx | 48 +++++++++------ functions/onprem/orborus/go.mod | 2 +- functions/onprem/orborus/go.sum | 2 + functions/onprem/orborus/orborus.go | 9 ++- 9 files changed, 148 insertions(+), 38 deletions(-) diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index c3162303..be5bee26 100755 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -1371,9 +1371,16 @@ class AppBase: returns = [] for item in value: - self.logger.info("VALUE: %s" % item) + self.logger.info("FILE VALUE: %s" % item) + # Check if item is a dict, and if it is, check if it has the key "id" + if isinstance(item, dict): + if "file_id" in item: + item = item["file_id"] + elif "id" in item: + item = item["id"] + if len(item) != 36 and not item.startswith("file_"): - self.logger.info("Bad length for file value %s" % item) + self.logger.info("Bad length for file value: '%s'" % item) continue #return { # "filename": "", diff --git a/frontend/src/components/CacheView.jsx b/frontend/src/components/CacheView.jsx index 607e0030..8810029a 100644 --- a/frontend/src/components/CacheView.jsx +++ b/frontend/src/components/CacheView.jsx @@ -457,7 +457,7 @@ const CacheView = (props) => { const validate = validateJson(data.value); return ( - + { style={{ minWidth: 400, maxWidth: 400, - overflowX: "auto", - overflowY: "hidden", }} primary={validate.valid ? { const [downloadFolder, setDownloadFolder] = React.useState("translation_standards"); //const alert = useAlert(); - const allowedFileTypes = ["txt", "py", "yaml", "yml","json", "html", "js", "csv", "log"] + const allowedFileTypes = ["txt", "py", "yaml", "yml","json", "html", "js", "csv", "log", "eml", "msg", "md", "xml", "sh", "bat", "ps1", "psm1", "psd1", "ps1xml", "pssc", "psc1"] var upload = ""; const handleKeyDown = (event) => { diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx index 4890918f..099cbeba 100755 --- a/frontend/src/views/Admin.jsx +++ b/frontend/src/views/Admin.jsx @@ -1155,7 +1155,7 @@ If you're interested, please let me know a time that works for you, or set up a }) .then((responseJson) => { if (responseJson.success === false) { - toast("Failed getting your org. If this persists, please contact support."); + //toast("Failed getting your org. If this persists, please contact support."); } else { const { subOrgs, parentOrg } = responseJson; setSubOrgs(subOrgs); @@ -1164,7 +1164,7 @@ If you're interested, please let me know a time that works for you, or set up a }) .catch((error) => { console.log("Error getting sub orgs: ", error); - toast("Error getting sub organizations"); + //toast("Error getting sub organizations"); }); }; @@ -2846,13 +2846,20 @@ If you're interested, please let me know a time that works for you, or set up a : null} {isCloud ? { - toast("Region change is not implemented yet for users. Please contact support.") + toast("Region change is not directly implemented yet, and requires support help.") + + if (window.drift !== undefined) { + window.drift.api.startInteraction({ + interactionId: 386411, + }) + } }} > {regiontag} @@ -3924,7 +3931,7 @@ If you're interested, please let me know a time that works for you, or set up a Schedules used in Workflows. Makes locating and control easier.{" "} @@ -4528,7 +4535,7 @@ If you're interested, please let me know a time that works for you, or set up a style={{ minWidth: 150, maxWidth: 150 }} /> { }); }; + // POST to /api/v1/workflows + const createWorkflow = (workflow, trigger_index) => { + fetch(globalUrl + "/api/v1/workflows", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(workflow), + credentials: "include", + }) + .then((response) => { + if (response.status === 200) { + getAvailableWorkflows(trigger_index) + } + + return response.json(); + }) + .then((responseJson) => { + if (responseJson.id !== undefined && responseJson.id !== null && responseJson.id.length > 0) { + toast("Successfully created workflow"); + + handleWorkflowSelectionUpdate({ target: { value: responseJson } }, true) + } + }) + .catch((error) => { + console.log("Create workflow error: ", error.toString()) + }) + } + const UserinputSidebar = () => { if (Object.getOwnPropertyNames(selectedTrigger).length > 0 && workflow.triggers[selectedTriggerIndex] !== undefined) { if ( @@ -13229,7 +13259,7 @@ const AngularWorkflow = (defaultprops) => { /> {workflow.triggers[selectedTriggerIndex].parameters[2] !== undefined && workflow.triggers[selectedTriggerIndex].parameters[2].value.includes("subflow") ? ( -
+
{workflows === undefined || workflows === null || workflows.length === 0 ? null : ( @@ -13316,7 +13346,29 @@ const AngularWorkflow = (defaultprops) => { }} /> )} -
+ + {/* Button for making a new workflow to attach */} + + +
) : null} {workflow.triggers[selectedTriggerIndex].parameters[2] !== undefined && @@ -16202,11 +16254,13 @@ const AngularWorkflow = (defaultprops) => { Env      + { window.open("/admin?tab=environments", "_blank") }}> {executionData.workflow.actions[0].environment} + : null} {executionData.status !== undefined && @@ -16877,6 +16931,30 @@ const AngularWorkflow = (defaultprops) => { return "" } + // Check if array with json inside to handle one item at a time~ + if (typeof result === "object" && result.length !== undefined) { + if (result.length > 0) { + // Check type inside + if (typeof result[0] === "object") { + result = result[0] + } + } + } + + if (result.success === true && result.status === 200) { + if (result.body !== undefined && result.body !== null) { + const stringbody = result.body.toString() + if ((stringbody.startsWith("{") && stringbody.endsWith("}")) || (stringbody.startsWith("[") && stringbody.endsWith("]"))) { + return "" + } + + if (stringbody.length > 1000) { + return "Body looks to be big in a standard format. Consider using the 'To File' parameter to automatically make it into a file." + } + } else { + } + } + // Validate and check for newlines if (result.success !== false) { @@ -16894,7 +16972,8 @@ const AngularWorkflow = (defaultprops) => { } return "" - } + } + try { stringjson = JSON.stringify(result) diff --git a/frontend/src/views/Workflows.jsx b/frontend/src/views/Workflows.jsx index 03fab69d..bf21e96b 100755 --- a/frontend/src/views/Workflows.jsx +++ b/frontend/src/views/Workflows.jsx @@ -1018,9 +1018,9 @@ const Workflows = (props) => { data.default_return_value, data, false, - [], - "", - data.status + [], + "", + data.status ).then((response) => { if (response !== undefined) { toast(`Successfully imported ${data.name}`); @@ -1483,17 +1483,9 @@ const Workflows = (props) => { const sanitizeWorkflow = (data) => { data = JSON.parse(JSON.stringify(data)); - data["owner"] = ""; console.log("Sanitize start: ", data); data = deduplicateIds(data); - data["org"] = []; - data["org_id"] = ""; - data["execution_org"] = {}; - - // These are backwards.. True = saved before. Very confuse. - data["previously_saved"] = false; - data["first_save"] = false; console.log("Sanitize end: ", data); return data; @@ -1508,14 +1500,24 @@ const Workflows = (props) => { let exportFileDefaultName = data.name + ".json"; + data["owner"] = ""; + data["org"] = []; + data["org_id"] = ""; + data["execution_org"] = {}; + + // These are backwards.. True = saved before. Very confuse. + data["previously_saved"] = false; + data["first_save"] = false; + if (sanitize === true) { data = sanitizeWorkflow(data); if (data.subflows !== null && data.subflows !== undefined) { toast( "Not exporting with subflows when sanitizing. Please manually export them." - ); - data.subflows = []; + ) + + data.subflows = [] } // for (var key in data.subflows) { @@ -1527,7 +1529,7 @@ const Workflows = (props) => { // Add correct ID's for triggers // Add mag - data.status = "test" + data.status = "test" let dataStr = JSON.stringify(data); let dataUri = "data:application/json;charset=utf-8," + encodeURIComponent(dataStr); @@ -2220,6 +2222,7 @@ const Workflows = (props) => { inputblogpost, inputstatus, ) => { + var method = "POST"; var extraData = ""; var workflowdata = {}; @@ -2232,6 +2235,10 @@ const Workflows = (props) => { console.log("REMOVING OWNER"); workflowdata["owner"] = ""; + workflowdata["org"] = []; + workflowdata["org_id"] = ""; + workflowdata["execution_org"] = {}; + workflowdata["previously_saved"] = false; // FIXME: Loop triggers and turn them off? } @@ -2240,8 +2247,9 @@ const Workflows = (props) => { if (tags !== undefined) { workflowdata["tags"] = tags; } - workflowdata["blogpost"] = inputblogpost - workflowdata["status"] = inputstatus + + workflowdata["blogpost"] = inputblogpost + workflowdata["status"] = inputstatus if (defaultReturnValue !== undefined) { workflowdata["default_return_value"] = defaultReturnValue; @@ -2320,7 +2328,7 @@ const Workflows = (props) => { if (file.type !== "application/json") { if (file.type !== undefined) { toast("File has to contain valid json"); - setSubmitLoading(false) + setSubmitLoading(false) } continue; @@ -2338,7 +2346,7 @@ const Workflows = (props) => { return; } - console.log("File being loaded: ", data.name); + console.log("File being loaded: ", data.name); // Initialize the workflow itself setNewWorkflow( @@ -2359,6 +2367,10 @@ const Workflows = (props) => { data.first_save = false; data.previously_saved = false; data.is_valid = false; + data.org_id = userdata.active_org.id + data.org = [] + data.execution_org = {} + // Actually create it setNewWorkflow( diff --git a/functions/onprem/orborus/go.mod b/functions/onprem/orborus/go.mod index 6d4e457c..888c95f5 100644 --- a/functions/onprem/orborus/go.mod +++ b/functions/onprem/orborus/go.mod @@ -7,7 +7,7 @@ go 1.19 require ( github.com/docker/docker v23.0.3+incompatible github.com/satori/go.uuid v1.2.0 - github.com/shuffle/shuffle-shared v0.5.93 + github.com/shuffle/shuffle-shared v0.5.98 k8s.io/api v0.28.1 k8s.io/apimachinery v0.28.1 k8s.io/client-go v0.28.1 diff --git a/functions/onprem/orborus/go.sum b/functions/onprem/orborus/go.sum index 9e8931bc..78bb4045 100644 --- a/functions/onprem/orborus/go.sum +++ b/functions/onprem/orborus/go.sum @@ -350,6 +350,8 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shuffle/shuffle-shared v0.5.93 h1:fZf9s2cEgDoyYXXvPYVeNh8UysuSlywQkc54IXkNL0k= github.com/shuffle/shuffle-shared v0.5.93/go.mod h1:Lg6/+qjQlWzNKwj4/4ATpvScyP2JQGLkTPlNlRM6RJk= +github.com/shuffle/shuffle-shared v0.5.98 h1:0qG/1UZZVmY+wIJBuC9bnFjCITJBr7iKLG5ZibpBkTI= +github.com/shuffle/shuffle-shared v0.5.98/go.mod h1:Lg6/+qjQlWzNKwj4/4ATpvScyP2JQGLkTPlNlRM6RJk= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index 25412d05..7e01b46c 100755 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -829,7 +829,7 @@ func deployWorker(image string, identifier string, env []string, executionReques } if err != nil { - log.Printf("[ERROR] Failed to start worker container in environment %s: %s", environment, err) + log.Printf("[ERROR] Failed to start worker container in environment '%s': %s", environment, err) return err } else { log.Printf("[INFO][%s] Worker Container created (2). Environment %s: docker logs %s", executionRequest.ExecutionId, environment, cont.ID) @@ -1672,6 +1672,11 @@ func main() { continue } + if len(execution.ExecutionId) == 0 { + log.Printf("[WARNING] Execution ID is empty: %#v", execution) + continue + } + if execution.Status == "ABORT" || execution.Status == "FAILED" { log.Printf("[INFO] Executionstatus issue: ", execution.Status) } @@ -1767,7 +1772,7 @@ func main() { toBeRemoved.Data = append(toBeRemoved.Data, execution) executionIds = append(executionIds, execution.ExecutionId) } else { - log.Printf("[WARNING] Execution ID %s failed to deploy: %s", execution.ExecutionId, err) + log.Printf("[WARNING] Execution ID '%s' failed to deploy: %s", execution.ExecutionId, err) } }