From 6bc64f3657c672f9b32436fb7f7187bfdb4aca3f Mon Sep 17 00:00:00 2001 From: Hari Krishna Date: Wed, 6 Mar 2024 16:19:51 +0530 Subject: [PATCH 1/2] Merge pull request #1 from tesla999936/main added an endpoint to get user apps --- backend/go-app/main.go | 1 + backend/go-app/walkoff.go | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 43d9eb53..71d30988 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -4785,6 +4785,7 @@ func initHandlers() { r.HandleFunc("/api/v1/users/checkusers", checkAdminLogin).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/getinfo", handleInfo).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/users/apps", getUserApps).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/generateapikey", shuffle.HandleApiGeneration).Methods("GET", "POST", "OPTIONS") r.HandleFunc("/api/v1/users/logout", shuffle.HandleLogout).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users/getsettings", shuffle.HandleSettings).Methods("GET", "OPTIONS") diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 40f9ba3a..ed32e90d 100755 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -2404,6 +2404,70 @@ func setExampleresult(ctx context.Context, result shuffle.AppExecutionExample) e return nil } +func getUserApps(resp http.ResponseWriter, request *http.Request) { + cors := shuffle.HandleCors(resp, request) + if cors { + return + } + + ctx := context.Background() + user, userErr := shuffle.HandleApiAuthentication(resp, request) + if userErr != nil { + log.Printf("[WARNING] Api authentication failed in get all apps - this does NOT require auth in the cloud.: %s", userErr) + resp.WriteHeader(401) + resp.Write([]byte(`{"success": false}`)) + return + } + + workflowapps, err := shuffle.GetAllWorkflowApps(ctx, 1000, 0) + if err != nil { + log.Printf("[WARNING] Failed getting apps (getworkflowapps): %s", err) + resp.WriteHeader(401) + resp.Write([]byte(`{"success": false}`)) + return + } + + filteredApps := workflowapps[:0] + for _, app := range workflowapps { + if app.Owner == user.Id { + filteredApps = append(filteredApps, app) + } else if app.Contributors != nil { + for _, contributor := range app.Contributors { + if contributor == user.Id { + filteredApps = append(filteredApps, app) + } + } + } + } + + if len(user.PrivateApps) > 0 { + for _, item := range user.PrivateApps { + found := false + for _, app := range filteredApps { + if item.ID == app.ID || !(item.Owner == user.Id) { + found = true + break + } + } + + if !found { + filteredApps = append(filteredApps, item) + } + } + } + + newbody, err := json.Marshal(filteredApps) + if err != nil { + log.Printf("[ERROR] Failed unmarshalling all newapps: %s", err) + resp.WriteHeader(401) + resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed unpacking workflow apps"}`))) + return + } + + resp.WriteHeader(200) + resp.Write(newbody) +} + func getWorkflowApps(resp http.ResponseWriter, request *http.Request) { cors := shuffle.HandleCors(resp, request) if cors { From 40d84087cdc0fad5b338538d99f63459cc27e7d6 Mon Sep 17 00:00:00 2001 From: Hari Krishna Date: Sat, 9 Mar 2024 18:00:10 +0530 Subject: [PATCH 2/2] Merge pull request #2 from tesla999936/main reverting getUserApps --- backend/go-app/main.go | 2 +- backend/go-app/walkoff.go | 64 --------------------------------------- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 71d30988..0c9da252 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -4785,7 +4785,7 @@ func initHandlers() { r.HandleFunc("/api/v1/users/checkusers", checkAdminLogin).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/getinfo", handleInfo).Methods("GET", "OPTIONS") - r.HandleFunc("/api/v1/users/apps", getUserApps).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/users/apps", shuffle.HandleGetUserApps).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/users/generateapikey", shuffle.HandleApiGeneration).Methods("GET", "POST", "OPTIONS") r.HandleFunc("/api/v1/users/logout", shuffle.HandleLogout).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/users/getsettings", shuffle.HandleSettings).Methods("GET", "OPTIONS") diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index ed32e90d..40f9ba3a 100755 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -2404,70 +2404,6 @@ func setExampleresult(ctx context.Context, result shuffle.AppExecutionExample) e return nil } -func getUserApps(resp http.ResponseWriter, request *http.Request) { - cors := shuffle.HandleCors(resp, request) - if cors { - return - } - - ctx := context.Background() - user, userErr := shuffle.HandleApiAuthentication(resp, request) - if userErr != nil { - log.Printf("[WARNING] Api authentication failed in get all apps - this does NOT require auth in the cloud.: %s", userErr) - resp.WriteHeader(401) - resp.Write([]byte(`{"success": false}`)) - return - } - - workflowapps, err := shuffle.GetAllWorkflowApps(ctx, 1000, 0) - if err != nil { - log.Printf("[WARNING] Failed getting apps (getworkflowapps): %s", err) - resp.WriteHeader(401) - resp.Write([]byte(`{"success": false}`)) - return - } - - filteredApps := workflowapps[:0] - for _, app := range workflowapps { - if app.Owner == user.Id { - filteredApps = append(filteredApps, app) - } else if app.Contributors != nil { - for _, contributor := range app.Contributors { - if contributor == user.Id { - filteredApps = append(filteredApps, app) - } - } - } - } - - if len(user.PrivateApps) > 0 { - for _, item := range user.PrivateApps { - found := false - for _, app := range filteredApps { - if item.ID == app.ID || !(item.Owner == user.Id) { - found = true - break - } - } - - if !found { - filteredApps = append(filteredApps, item) - } - } - } - - newbody, err := json.Marshal(filteredApps) - if err != nil { - log.Printf("[ERROR] Failed unmarshalling all newapps: %s", err) - resp.WriteHeader(401) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed unpacking workflow apps"}`))) - return - } - - resp.WriteHeader(200) - resp.Write(newbody) -} - func getWorkflowApps(resp http.ResponseWriter, request *http.Request) { cors := shuffle.HandleCors(resp, request) if cors {