Fixed app creation, RE: json issue

This commit is contained in:
frikky
2020-06-16 17:50:28 +02:00
parent 8ea19ea530
commit d087a53bd6
6 changed files with 49 additions and 18 deletions
+3 -9
View File
@@ -339,14 +339,7 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
bodyAddin = ", data=body"
// FIXME: Does JSON data work?
bodyFormatter = `
if (body.startswith("{") and body.endswith("}")) or (body.startswith("[") and body.endswith("]")):
try:
body = json.dumps(body)
except:
pass
`
break
bodyFormatter = `body = " ".join(body.strip().split())`
}
}
@@ -375,13 +368,14 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
// Extra param for url if it's changeable
// Extra param for authentication scheme(s)
// The last weird one is the body.. Tabs & spaces sucks.
data := fmt.Sprintf(` async def %s(self%s%s%s%s%s%s):
%s
url=f"%s%s"
%s
%s
%s
%s
%s
return requests.%s(url, headers=headers%s%s%s).text
`,
functionname,
+13 -1
View File
@@ -161,6 +161,7 @@ type User struct {
Verified bool `datastore:"verified,noindex" json:"verified"`
PrivateApps []WorkflowApp `datastore:"privateapps" json:"privateapps":`
Role string `datastore:"role" json:"role"`
Roles []string `datastore:"roles" json:"roles"`
VerificationToken string `datastore:"verification_token" json:"verification_token"`
ApiKey string `datastore:"apikey" json:"apikey"`
ResetReference string `datastore:"reset_reference" json:"reset_reference"`
@@ -169,7 +170,7 @@ type User struct {
Authentication []UserAuth `datastore:"authentication,noindex" json:"authentication"`
ResetTimeout int64 `datastore:"reset_timeout,noindex" json:"reset_timeout"`
Id string `datastore:"id" json:"id"`
Orgs string `datastore:"orgs" json:"orgs"`
Orgs []string `datastore:"orgs" json:"orgs"`
CreationTime int64 `datastore:"creation_time" json:"creation_time"`
Active bool `datastore:"active" json:"active"`
}
@@ -1077,12 +1078,15 @@ func handleRegister(resp http.ResponseWriter, request *http.Request) {
newUser.Verified = false
newUser.CreationTime = time.Now().Unix()
newUser.Active = true
newUser.Orgs = []string{"default"}
// FIXME - Remove this later
if count == 0 {
newUser.Role = "admin"
newUser.Roles = []string{"admin"}
} else {
newUser.Role = "user"
newUser.Roles = []string{"user"}
}
// set limits
@@ -5953,6 +5957,14 @@ func runInit(ctx context.Context) {
continue
}
if len(user.Role) > 0 {
user.Roles = append(user.Roles, user.Role)
}
if len(user.Orgs) == 0 {
user.Orgs = []string{"default"}
}
err = setUser(ctx, &user)
if err != nil {
log.Printf("Failed to reset user")
+2 -2
View File
@@ -2923,8 +2923,8 @@ func getWorkflowAppConfig(resp http.ResponseWriter, request *http.Request) {
return
}
//log.Printf("%#v", parsedApi)
log.Printf("API LEN: %d, ID: %s", len(parsedApi.Body), fileId)
// log.Printf("%#v", parsedApi)
// log.Printf("API LEN: %d, ID: %s", len(parsedApi.Body), fileId)
//log.Printf("Parsed API: %#v", parsedApi)
if len(parsedApi.ID) > 0 {
+28 -3
View File
@@ -31,6 +31,7 @@ const Admin = (props) => {
const [users, setUsers] = React.useState([]);
const [environments, setEnvironments] = React.useState([]);
const [schedules, setSchedules] = React.useState([])
const [selectedUser, setSelectedUser] = React.useState({})
const alert = useAlert()
@@ -286,6 +287,22 @@ const Admin = (props) => {
modalUser[field] = value
}
const editUserModal =
<Dialog modal
open={modalOpen}
onClose={() => {setModalOpen(false)}}
PaperProps={{
style: {
backgroundColor: surfaceColor,
color: "white",
minWidth: "800px",
minHeight: "320px",
},
}}
>
<DialogTitle><span style={{color: "white"}}>Add user</span></DialogTitle>
</Dialog>
const modalView =
<Dialog modal
open={modalOpen}
@@ -452,17 +469,24 @@ const Admin = (props) => {
<ListItemText
primary={data.active ? "True" : "False"}
style={{minWidth: 180, maxWidth: 180}}
onClick={() => console.log("Should set user to active")}
/>
<ListItemText>
<ListItemText style={{display: "flex"}}>
<Button
style={{}}
variant="contained"
variant="outlined"
color="primary"
onClick={() => deleteUser(data)}
>
{data.active ? "Deactivate" : "Activate"}
</Button>
<Button
style={{}}
variant="outlined"
color="primary"
onClick={() => deleteUser(data)}
>
Edit
</Button>
</ListItemText>
</ListItem>
)
@@ -581,6 +605,7 @@ const Admin = (props) => {
return (
<div>
{modalView}
{editUserModal}
{data}
</div>
)
+2 -2
View File
@@ -639,7 +639,7 @@ const AppCreator = (props) => {
}
}
if (item.body.length > 0) {
if (item.body !== undefined && item.body.length > 0) {
const required = false
newitem = {
"in": "body",
@@ -1525,7 +1525,7 @@ const AppCreator = (props) => {
// <img src={file} id="logo" style={{width: "100%", height: "100%"}} />
const imageData = file.length > 0 ? file : fileBase64
const imageInfo = <img src={imageData} alt="Click to upload an image" id="logo" style={{maxWidth: 174, maxHeight: 174,}} />
const imageInfo = <img src={imageData} alt="Click to upload an image (174x174)" id="logo" style={{maxWidth: 174, maxHeight: 174,}} />
// Random names for type & autoComplete. Didn't research :^)
const landingpageDataBrowser =
+1 -1
View File
@@ -183,7 +183,7 @@ const Settings = (props) => {
<div style={{display: "flex", marginTop: "80px"}}>
<Paper style={boxStyle}>
<h2>APIKEY</h2>
<Link to="/docs/api#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is the API key used for?</Link>
<Link to="/docs/API#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is the API key used for?</Link>
<TextField
style={{backgroundColor: inputColor, flex: "1"}}
InputProps={{