From d087a53bd6319a67eaa6088c569b139949ced1ff Mon Sep 17 00:00:00 2001 From: frikky Date: Tue, 16 Jun 2020 17:50:28 +0200 Subject: [PATCH] Fixed app creation, RE: json issue --- backend/go-app/codegen.go | 12 +++--------- backend/go-app/main.go | 14 +++++++++++++- backend/go-app/walkoff.go | 4 ++-- frontend/src/Admin.js | 31 ++++++++++++++++++++++++++++--- frontend/src/AppCreator.js | 4 ++-- frontend/src/SettingsPage.js | 2 +- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/backend/go-app/codegen.go b/backend/go-app/codegen.go index 7a728aa9..9e9ad000 100644 --- a/backend/go-app/codegen.go +++ b/backend/go-app/codegen.go @@ -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, diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 884ee356..8236a1d6 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -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") diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 2dc041bf..0c8d4a82 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -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 { diff --git a/frontend/src/Admin.js b/frontend/src/Admin.js index 1790c87e..7c07c0fd 100644 --- a/frontend/src/Admin.js +++ b/frontend/src/Admin.js @@ -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 = + {setModalOpen(false)}} + PaperProps={{ + style: { + backgroundColor: surfaceColor, + color: "white", + minWidth: "800px", + minHeight: "320px", + }, + }} + > + Add user + + const modalView = { console.log("Should set user to active")} /> - + + ) @@ -581,6 +605,7 @@ const Admin = (props) => { return (
{modalView} + {editUserModal} {data}
) diff --git a/frontend/src/AppCreator.js b/frontend/src/AppCreator.js index 2203d68d..c44b7168 100644 --- a/frontend/src/AppCreator.js +++ b/frontend/src/AppCreator.js @@ -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) => { // const imageData = file.length > 0 ? file : fileBase64 - const imageInfo = + const imageInfo = // Random names for type & autoComplete. Didn't research :^) const landingpageDataBrowser = diff --git a/frontend/src/SettingsPage.js b/frontend/src/SettingsPage.js index 61577420..d03f928f 100644 --- a/frontend/src/SettingsPage.js +++ b/frontend/src/SettingsPage.js @@ -183,7 +183,7 @@ const Settings = (props) => {

APIKEY

- What is the API key used for? + What is the API key used for?