#149: Properly fixed app sdk loop issues
This commit is contained in:
+112
-56
@@ -361,11 +361,99 @@ class AppBase:
|
||||
newlist.append("parsing_error")
|
||||
return " ".join(newlist)
|
||||
|
||||
def recurse_json(basejson, parsersplit):
|
||||
match = "#(\d+):?-?([0-9a-z]+)?#?"
|
||||
print("Split: %s\n%s" % (parsersplit, basejson))
|
||||
try:
|
||||
outercnt = 0
|
||||
for value in parsersplit:
|
||||
print("VALUE: %s\n" % value)
|
||||
actualitem = re.findall(match, value, re.MULTILINE)
|
||||
if value == "#":
|
||||
newvalue = []
|
||||
for innervalue in basejson:
|
||||
# 1. Check the next item (message)
|
||||
# 2. Call this function again
|
||||
|
||||
try:
|
||||
ret = recurse_json(innervalue, parsersplit[outercnt+1:])
|
||||
except IndexError:
|
||||
print("INDEXERROR: ", parsersplit[outercnt])
|
||||
#ret = innervalue
|
||||
ret = recurse_json(innervalue, parsersplit[outercnt:])
|
||||
|
||||
print(ret)
|
||||
#exit()
|
||||
newvalue.append(ret)
|
||||
|
||||
return newvalue
|
||||
elif len(actualitem) > 0:
|
||||
# FIXME: This is absolutely not perfect.
|
||||
print("IN HERE: ", actualitem)
|
||||
|
||||
newvalue = []
|
||||
firstitem = actualitem[0][0]
|
||||
seconditem = actualitem[0][1]
|
||||
if seconditem == "":
|
||||
print("In first")
|
||||
basejson = basejson[int(firstitem)]
|
||||
else:
|
||||
if seconditem == "max":
|
||||
seconditem = len(basejson)
|
||||
if seconditem == "min":
|
||||
seconditem = 0
|
||||
|
||||
newvalue = []
|
||||
for i in range(int(firstitem), int(seconditem)):
|
||||
# 1. Check the next item (message)
|
||||
# 2. Call this function again
|
||||
print("Base: %s" % basejson[i])
|
||||
|
||||
try:
|
||||
ret = recurse_loop(basejson[i], parsersplit[outercnt+1:])
|
||||
except IndexError:
|
||||
print("INDEXERROR: ", parsersplit[outercnt])
|
||||
#ret = innervalue
|
||||
ret = recurse_loop(innervalue, parsersplit[outercnt:])
|
||||
|
||||
print(ret)
|
||||
#exit()
|
||||
newvalue.append(ret)
|
||||
|
||||
return newvalue
|
||||
|
||||
# FIXME: Add specific loop for other indexes
|
||||
else:
|
||||
#print("BEFORE NORMAL VALUE: ", basejson, value)
|
||||
if len(value) == 0:
|
||||
return basejson
|
||||
|
||||
if isinstance(basejson[value], str):
|
||||
print(f"LOADING STRING '%s' AS JSON" % basejson[value])
|
||||
try:
|
||||
basejson = json.loads(basejson[value])
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print("RETURNING BECAUSE '%s' IS A NORMAL STRING" % basejson[value])
|
||||
return basejson[value]
|
||||
else:
|
||||
basejson = basejson[value]
|
||||
|
||||
outercnt += 1
|
||||
|
||||
except KeyError as e:
|
||||
print("Lower keyerror: %s" % e)
|
||||
#return basejson
|
||||
#return "KeyError: Couldn't find key: %s" % e
|
||||
|
||||
return basejson
|
||||
|
||||
# Takes a workflow execution as argument
|
||||
# Returns a string if the result is single, or a list if it's a list
|
||||
def get_json_value(execution_data, input_data):
|
||||
parsersplit = input_data.split(".")
|
||||
actionname = parsersplit[0][1:].replace(" ", "_", -1)
|
||||
#Actionname: Start_node
|
||||
|
||||
print(f"Actionname: {actionname}")
|
||||
|
||||
# 1. Find the action
|
||||
@@ -433,59 +521,7 @@ class AppBase:
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
return baseresult
|
||||
|
||||
# This whole thing should be recursive.
|
||||
try:
|
||||
cnt = 0
|
||||
for value in parsersplit[1:]:
|
||||
cnt += 1
|
||||
|
||||
print("VALUE: %s" % value)
|
||||
if value == "#":
|
||||
# FIXME - not recursive - should go deeper if there are more #
|
||||
print("HANDLE RECURSIVE LOOP OF %s" % basejson)
|
||||
returnlist = []
|
||||
try:
|
||||
for innervalue in basejson:
|
||||
print("Value: %s" % innervalue[parsersplit[cnt+1]])
|
||||
returnlist.append(innervalue[parsersplit[cnt+1]])
|
||||
except IndexError as e:
|
||||
print("Indexerror inner: %s" % e)
|
||||
# Basically means its a normal list, not a crazy one :)
|
||||
# Custom format for ${name[0,1,2,...]}$
|
||||
indexvalue = "${NO_SPLITTER%s}$" % json.dumps(basejson)
|
||||
if len(returnlist) > 0:
|
||||
indexvalue = "${NO_SPLITTER%s}$" % json.dumps(returnlist)
|
||||
|
||||
print("INDEXVAL: ", indexvalue)
|
||||
return indexvalue
|
||||
except TypeError as e:
|
||||
print("TypeError inner: %s" % e)
|
||||
|
||||
# Example format: ${[]}$
|
||||
parseditem = "${%s%s}$" % (parsersplit[cnt+1], json.dumps(returnlist))
|
||||
print("PARSED LOOP ITEM: %s" % parseditem)
|
||||
return parseditem
|
||||
|
||||
else:
|
||||
print("BEFORE NORMAL VALUE: ", basejson, value)
|
||||
if len(value) == 0:
|
||||
return basejson
|
||||
|
||||
if isinstance(basejson[value], str):
|
||||
print(f"LOADING STRING '%s' AS JSON" % basejson[value])
|
||||
try:
|
||||
basejson = json.loads(basejson[value])
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print("RETURNING BECAUSE '%s' IS A NORMAL STRING" % basejson[value])
|
||||
return basejson[value]
|
||||
else:
|
||||
basejson = basejson[value]
|
||||
|
||||
except KeyError as e:
|
||||
print("Lower keyerror: %s" % e)
|
||||
return "KeyError: Couldn't find key: %s" % e
|
||||
|
||||
return basejson
|
||||
return recurse_json(basejson, parsersplit[1:])
|
||||
|
||||
# Parses parameters sent to it and returns whether it did it successfully with the values found
|
||||
def parse_params(action, fullexecution, parameter):
|
||||
@@ -510,6 +546,7 @@ class AppBase:
|
||||
except IndexError:
|
||||
continue
|
||||
|
||||
# Handles for loops etc.
|
||||
value = get_json_value(fullexecution, to_be_replaced)
|
||||
if isinstance(value, str):
|
||||
parameter["value"] = parameter["value"].replace(to_be_replaced, value)
|
||||
@@ -849,7 +886,7 @@ class AppBase:
|
||||
replacement = replacement[1:len(replacement)-1]
|
||||
#except json.decoder.JSONDecodeError as e:
|
||||
|
||||
print("REPLACING %s with %s" % (key, replacement))
|
||||
#print("REPLACING %s with %s" % (key, replacement))
|
||||
#replacement = parse_wrapper_start(replacement)
|
||||
tmpitem = tmpitem.replace(key, replacement, -1)
|
||||
|
||||
@@ -911,6 +948,7 @@ class AppBase:
|
||||
results.append(json.loads(ret))
|
||||
json_object = True
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
#print("Json: %s" % e)
|
||||
results.append(ret)
|
||||
|
||||
# Dump the result as a string of a list
|
||||
@@ -920,7 +958,25 @@ class AppBase:
|
||||
if json_object:
|
||||
result = json.dumps(results)
|
||||
else:
|
||||
result = "[\""+"\", \"".join(results)+"\"]"
|
||||
result = "["
|
||||
for item in results:
|
||||
try:
|
||||
json.loads(item)
|
||||
result += item
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
# Common nested issue which puts " around everything
|
||||
try:
|
||||
tmpitem = item.replace("\\\"", "\"", -1)
|
||||
json.loads(tmpitem)
|
||||
result += tmpitem
|
||||
|
||||
except:
|
||||
result += "\"%s\"" % item
|
||||
|
||||
result += ", "
|
||||
|
||||
result = result[:-2]
|
||||
result += "]"
|
||||
else:
|
||||
print("Normal result?")
|
||||
result = results
|
||||
@@ -932,7 +988,7 @@ class AppBase:
|
||||
action_result["result"] = result
|
||||
|
||||
self.logger.debug(f"Executed {action['label']}-{action['id']} with result: {result}")
|
||||
self.logger.debug(f"Data: %s" % action_result)
|
||||
#self.logger.debug(f"Data: %s" % action_result)
|
||||
except TypeError as e:
|
||||
print("TypeError issue: %s" % e)
|
||||
action_result["status"] = "FAILURE"
|
||||
|
||||
@@ -6467,11 +6467,6 @@ func init() {
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/api/v1/_ah/health", healthCheckHandler)
|
||||
|
||||
// Sends an email if the right things are specified
|
||||
r.HandleFunc("/functions/sendmail", handleSendalert).Methods("POST", "OPTIONS")
|
||||
r.HandleFunc("/functions/outlook/register", handleNewOutlookRegister).Methods("GET", "OPTIONS")
|
||||
r.HandleFunc("/functions/outlook/getFolders", handleGetOutlookFolders).Methods("GET", "OPTIONS")
|
||||
|
||||
// Make user related locations
|
||||
r.HandleFunc("/api/v1/users/generateapikey", handleApiGeneration).Methods("GET", "POST", "OPTIONS")
|
||||
r.HandleFunc("/api/v1/users/login", handleLogin).Methods("POST", "OPTIONS")
|
||||
|
||||
@@ -2042,16 +2042,14 @@ func cleanupExecutions(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
//if user.Role != "admin" {
|
||||
// resp.WriteHeader(401)
|
||||
// resp.Write([]byte(`{"success": false, "message": "Insufficient permissions"}`))
|
||||
// return
|
||||
//}
|
||||
|
||||
log.Printf("CLEANUP!")
|
||||
log.Printf("%#v", user)
|
||||
if user.Role != "admin" {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "message": "Insufficient permissions"}`))
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Removes three months from today
|
||||
timestamp := int64(time.Now().AddDate(0, -2, 0).Unix())
|
||||
log.Println(timestamp)
|
||||
@@ -2065,8 +2063,6 @@ func cleanupExecutions(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(len(workflowExecutions))
|
||||
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte("OK"))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
frontend:
|
||||
#build: ./frontend
|
||||
build: ./frontend
|
||||
image: frikky/shuffle:frontend
|
||||
container_name: shuffle-frontend
|
||||
hostname: shuffle-frontend
|
||||
|
||||
@@ -146,7 +146,7 @@ const App = (message, props) => {
|
||||
<Route exact path="/docs" render={props => { window.location.pathname = "/docs/about" }} />
|
||||
<Route exact path="/introduction" render={props => <Introduction isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} />
|
||||
<Route exact path="/introduction/:key" render={props => <Introduction isLoaded={isLoaded} globalUrl={globalUrl} {...props} />} />
|
||||
<Route exact path="/" render={props => { window.location.pathname = "/login" }} />
|
||||
<Route exact path="/" render={props => <LoginPage isLoggedIn={isLoggedIn} setIsLoggedIn={setIsLoggedIn} register={true} isLoaded={isLoaded} globalUrl={globalUrl} setCookie={setCookie} cookies={cookies} {...props} />} />
|
||||
</div>
|
||||
|
||||
// <div style={{backgroundColor: "rgba(21, 32, 43, 1)", color: "#fffff", minHeight: "100vh"}}>
|
||||
|
||||
@@ -195,7 +195,7 @@ const Header = props => {
|
||||
</Button>
|
||||
</Link>
|
||||
</ListItem>
|
||||
{userdata === undefined || userdata.orgs.length <= 1 ? null :
|
||||
{userdata === undefined || userdata.orgs === undefined || userdata.orgs === null || userdata.orgs.length <= 1 ? null :
|
||||
<ListItem>
|
||||
<Select
|
||||
SelectDisplayProps={{
|
||||
|
||||
Reference in New Issue
Block a user