From 1a2300acfee5922c583708728901440ae4562538 Mon Sep 17 00:00:00 2001 From: Rhys Berrow Date: Fri, 5 Apr 2024 13:33:42 +0100 Subject: [PATCH 1/3] Remove ability to launch v1 pattern --- authentication/auth.go | 90 +----------------------------------------- launch.go | 23 ++--------- templates/launch.html | 26 +++--------- 3 files changed, 11 insertions(+), 128 deletions(-) diff --git a/authentication/auth.go b/authentication/auth.go index ee1b31fe..16110aca 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -156,45 +156,6 @@ func getSurveyMetadataFromClaims(claimValues map[string][]string, data map[strin claims["survey_metadata"] = surveyMetadata } -func generateClaims(claimValues map[string][]string, launcherSchema surveys.LauncherSchema) (claims map[string]interface{}) { - - var roles []string - if rolesValues, ok := claimValues["roles"]; ok { - roles = rolesValues - } else { - roles = []string{"dumper"} - } - - claims = make(map[string]interface{}) - - claims["roles"] = roles - TxID, _ := uuid.NewV4() - claims["tx_id"] = TxID.String() - - for key, value := range claimValues { - if key != "roles" { - if value[0] != "" { - claims[key] = value[0] - } - } else { - claims[key] = value - } - } - if len(claimValues["form_type"]) > 0 && len(claimValues["eq_id"]) > 0 { - log.Println("Deleting schema name from claims") - delete(claims, "schema_name") - } else { - // When quicklaunching, schema_name will not be set, but launcherSchema will have the schema_name. - if len(claimValues["schema_name"]) == 0 && launcherSchema.Name != "" { - claims["schema_name"] = launcherSchema.Name - } - } - - log.Printf("Using claims: %s", claims) - - return claims -} - func generateClaimsV2(claimValues map[string][]string, schema QuestionnaireSchema) (claims map[string]interface{}) { var roles []string @@ -414,49 +375,6 @@ func getStringOrDefault(key string, values map[string][]string, defaultValue str return defaultValue } -// GenerateTokenFromDefaults coverts a set of DEFAULT values into a JWT -func GenerateTokenFromDefaults(schemaURL string, accountServiceURL string, accountServiceLogOutURL string, urlValues url.Values) (token string, error string) { - launcherSchema, validationError := launcherSchemaFromURL(schemaURL) - if validationError != "" { - return "", validationError - } - - claims := make(map[string]interface{}) - urlValues["account_service_url"] = []string{accountServiceURL} - urlValues["account_service_log_out_url"] = []string{accountServiceLogOutURL} - claims = generateClaims(urlValues, launcherSchema) - - requiredMetadata, error := getRequiredSchemaMetadata(launcherSchema) - if error != "" { - return "", fmt.Sprintf("getRequiredSchemaMetadata failed err: %v", error) - } - - for _, metadata := range requiredMetadata { - if metadata.Validator == "boolean" { - claims[metadata.Name] = getBooleanOrDefault(metadata.Name, urlValues, false) - continue - } - claims[metadata.Name] = getStringOrDefault(metadata.Name, urlValues, metadata.Default) - } - - jwtClaims := GenerateJwtClaims() - for key, v := range jwtClaims { - claims[key] = v - } - - schemaClaims := getSchemaClaims(launcherSchema) - for key, v := range schemaClaims { - claims[key] = v - } - - token, tokenError := generateTokenFromClaims(claims) - if tokenError != nil { - return token, fmt.Sprintf("GenerateTokenFromDefaults failed err: %v", tokenError) - } - - return token, "" -} - // GenerateTokenFromDefaultsV2 coverts a set of DEFAULT values into a JWT func GenerateTokenFromDefaultsV2(schemaURL string, accountServiceURL string, urlValues url.Values) (token string, error string) { launcherSchema, validationError := launcherSchemaFromURL(schemaURL) @@ -552,7 +470,7 @@ func TransformSchemaParamsToName(postValues url.Values) string { } // GenerateTokenFromPost converts a set of POST values into a JWT -func GenerateTokenFromPost(postValues url.Values, launchVersion2 bool) (string, string) { +func GenerateTokenFromPost(postValues url.Values) (string, string) { log.Println("POST received: ", postValues) schemaName := TransformSchemaParamsToName(postValues) @@ -568,11 +486,7 @@ func GenerateTokenFromPost(postValues url.Values, launchVersion2 bool) (string, claims := make(map[string]interface{}) - if launchVersion2 { - claims = generateClaimsV2(postValues, schema) - } else { - claims = generateClaims(postValues, launcherSchema) - } + claims = generateClaimsV2(postValues, schema) jwtClaims := GenerateJwtClaims() for key, v := range jwtClaims { diff --git a/launch.go b/launch.go index 6207c2bb..d775fd02 100644 --- a/launch.go +++ b/launch.go @@ -141,11 +141,7 @@ func redirectURL(w http.ResponseWriter, r *http.Request) { token := "" err := "" - if launchVersion == "v2" { - token, err = authentication.GenerateTokenFromPost(r.PostForm, true) - } else { - token, err = authentication.GenerateTokenFromPost(r.PostForm, false) - } + token, err = authentication.GenerateTokenFromPost(r.PostForm) if err != "" { http.Error(w, err, 500) @@ -167,20 +163,11 @@ func redirectURL(w http.ResponseWriter, r *http.Request) { func quickLauncherHandler(w http.ResponseWriter, r *http.Request) { hostURL := settings.Get("SURVEY_RUNNER_URL") accountServiceURL := getAccountServiceURL(r) - AccountServiceLogOutURL := getAccountServiceURL(r) urlValues := r.URL.Query() schemaURL := urlValues.Get("schema_url") - version := urlValues.Get("version") - launchVersion2 := true defaultValues := authentication.GetDefaultValues() - if version == "" { - urlValues.Add("version", defaultValues["version"]) - } else if version == "v1" { - launchVersion2 = false - } else { - urlValues.Add("version", version) - } + urlValues.Add("version", defaultValues["version"]) log.Println("Quick launch request received", schemaURL) @@ -195,11 +182,7 @@ func quickLauncherHandler(w http.ResponseWriter, r *http.Request) { token := "" err := "" - if launchVersion2 { - token, err = authentication.GenerateTokenFromDefaultsV2(schemaURL, accountServiceURL, urlValues) - } else { - token, err = authentication.GenerateTokenFromDefaults(schemaURL, accountServiceURL, AccountServiceLogOutURL, urlValues) - } + token, err = authentication.GenerateTokenFromDefaultsV2(schemaURL, accountServiceURL, urlValues) if err != "" { http.Error(w, err, 400) diff --git a/templates/launch.html b/templates/launch.html index 42e13767..e9991675 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -10,7 +10,6 @@

Launch a survey

@@ -269,27 +268,14 @@

Runner Data

} function includeSurveyMetadataFields(schema_name, survey_type) { - let launchPattern = document.querySelector("#launch_pattern").value - let eqIdValue = schema_name.split('_')[0] let formTypeValue = schema_name.split("_").slice(1).join("_") - if (launchPattern === "v1") { - document.querySelector('#survey_metadata_fields').innerHTML = `

${survey_type} Survey Metadata

-
- - -
-
- - -
` - } else { - document.querySelector('#survey_metadata_fields').innerHTML = `

${survey_type} Survey Metadata

-
- - -
` - } + document.querySelector('#survey_metadata_fields').innerHTML = `

${survey_type} Survey Metadata

+
+ + +
` + showSupplementaryData(true); document.querySelector('#survey_metadata_fields').classList.remove("supplementary-data--hidden"); From d00a86b782e88e7a847f2dcf0e6c87b382e3f8db Mon Sep 17 00:00:00 2001 From: Rhys Berrow Date: Mon, 8 Apr 2024 13:09:16 +0100 Subject: [PATCH 2/3] Update launch button --- templates/launch.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/launch.html b/templates/launch.html index e9991675..4f7fe1ab 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -9,9 +9,7 @@

Launch a survey

Launch Pattern
- +
Launch by Schema Name From 8a66b3ff2e781cfe9958faf440a060b94ba96a82 Mon Sep 17 00:00:00 2001 From: Rhys Berrow Date: Wed, 24 Apr 2024 11:06:31 +0100 Subject: [PATCH 3/3] Lint --- authentication/auth.go | 4 +--- static/javascript/launch.js | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/authentication/auth.go b/authentication/auth.go index ae136024..6b648543 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -484,9 +484,7 @@ func GenerateTokenFromPost(postValues url.Values) (string, string) { return "", fmt.Sprintf("getSchema failed err: %v", error) } - var claims map[string]interface{} - - claims = generateClaimsV2(postValues, schema) + var claims = generateClaimsV2(postValues, schema) jwtClaims := GenerateJwtClaims() for key, v := range jwtClaims { diff --git a/static/javascript/launch.js b/static/javascript/launch.js index bcba2475..501c711d 100644 --- a/static/javascript/launch.js +++ b/static/javascript/launch.js @@ -236,11 +236,12 @@ function showSubmitFlushButtons(show, justSubmit = false) { function includeSurveyMetadataFields(schema_name, survey_type) { let formTypeValue = schema_name.split("_").slice(1).join("_"); - document.querySelector('#survey_metadata_fields').innerHTML = `

${survey_type} Survey Metadata

+ document.querySelector("#survey_metadata_fields").innerHTML = + `

${survey_type} Survey Metadata

-
` + `; showSupplementaryData(true); document