From f13503452f73714ddd5f94babdb6ed2a8b4b7b85 Mon Sep 17 00:00:00 2001 From: petechd Date: Wed, 19 May 2021 08:54:58 +0100 Subject: [PATCH 1/8] Initial refactor --- surveys/surveys.go | 22 ++-------------------- templates/launch.html | 17 ----------------- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/surveys/surveys.go b/surveys/surveys.go index 9656b490..0ff4e5e8 100644 --- a/surveys/surveys.go +++ b/surveys/surveys.go @@ -24,8 +24,6 @@ type LauncherSchema struct { // LauncherSchemas is a separation of Test and Live schemas type LauncherSchemas struct { Business []LauncherSchema - CCS []LauncherSchema - Census []LauncherSchema Social []LauncherSchema Test []LauncherSchema Other []LauncherSchema @@ -63,13 +61,9 @@ func GetAvailableSchemas() LauncherSchemas { for _, launcherSchema := range runnerSchemas { if strings.HasPrefix(launcherSchema.Name, "test_") { schemaList.Test = append(schemaList.Test, launcherSchema) - } else if strings.HasPrefix(launcherSchema.Name, "census_") { - schemaList.Census = append(schemaList.Census, launcherSchema) - } else if strings.HasPrefix(launcherSchema.Name, "lms_") { + } else if strings.HasPrefix(launcherSchema.Name, "lms_") { schemaList.Social = append(schemaList.Social, launcherSchema) - } else if strings.HasPrefix(launcherSchema.Name, "ccs_") { - schemaList.CCS = append(schemaList.CCS, launcherSchema) - } else { + } else { schemaList.Business = append(schemaList.Business, launcherSchema) } } @@ -77,10 +71,8 @@ func GetAvailableSchemas() LauncherSchemas { schemaList.Other = getAvailableSchemasFromRegister() sort.Sort(ByFilename(schemaList.Business)) - sort.Sort(ByFilename(schemaList.Census)) sort.Sort(ByFilename(schemaList.Social)) sort.Sort(ByFilename(schemaList.Test)) - sort.Sort(ByFilename(schemaList.CCS)) return schemaList } @@ -183,16 +175,6 @@ func FindSurveyByName(name string) LauncherSchema { return survey } } - for _, survey := range availableSchemas.CCS { - if survey.Name == name { - return survey - } - } - for _, survey := range availableSchemas.Census { - if survey.Name == name { - return survey - } - } for _, survey := range availableSchemas.Social { if survey.Name == name { return survey diff --git a/templates/launch.html b/templates/launch.html index 98e5ca67..3ed131e7 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -15,16 +15,6 @@

Launch a survey

{{end}} - - {{range .Schemas.CCS}} - - {{end}} - - - {{range .Schemas.Census}} - - {{end}} - {{range .Schemas.Social}} @@ -140,13 +130,6 @@

Runner Data

// uuidv4: from https://github.com/kelektiv/node-uuid !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.uuidv4=e()}}(function(){return function e(n,r,o){function t(f,u){if(!r[f]){if(!n[f]){var a="function"==typeof require&&require;if(!u&&a)return a(f,!0);if(i)return i(f,!0);var d=new Error("Cannot find module '"+f+"'");throw d.code="MODULE_NOT_FOUND",d}var p=r[f]={exports:{}};n[f][0].call(p.exports,function(e){var r=n[f][1][e];return t(r?r:e)},p,p.exports,e,n,r,o)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f>>((3&n)<<3)&255;return i}}},{}],3:[function(e,n,r){function o(e,n,r){var o=n&&r||0;"string"==typeof e&&(n="binary"===e?new Array(16):null,e=null),e=e||{};var f=e.random||(e.rng||t)();if(f[6]=15&f[6]|64,f[8]=63&f[8]|128,n)for(var u=0;u<16;++u)n[o+u]=f[u];return n||i(f)}var t=e("./lib/rng"),i=e("./lib/bytesToUuid");n.exports=o},{"./lib/bytesToUuid":1,"./lib/rng":2}]},{},[3])(3)}); - const schema_name_census_regex = /^(census|ccs)_(household|individual|communal_establishment)_(gb_[a-z]{3})\s*$/ - const form_types = { - 'household': 'H', - 'individual': 'I', - 'communal_establishment': 'C', - } - function clearCensusClaims() { document.getElementById('census_claims').innerHTML = "" } From 0b73976299b57bbc7cb9afc1c484fe6868d83c3a Mon Sep 17 00:00:00 2001 From: petechd Date: Wed, 19 May 2021 09:05:37 +0100 Subject: [PATCH 2/8] Remove census schemas types from conditional other than test --- templates/launch.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/launch.html b/templates/launch.html index 3ed131e7..4569cb3f 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -172,7 +172,7 @@

Runner Data

const schema_name = document.getElementById("schema_name").value const is_census_test_schema = schema_name === "test_individual_response" - if (is_census_test_schema || schema_name.startsWith('census') || schema_name.startsWith('ccs')) { + if (is_census_test_schema) { includeCensusClaims(schema_name, is_census_test_schema) } else { clearCensusClaims() From 55e9d1f19d00e7651074dc625eac6268268b05c6 Mon Sep 17 00:00:00 2001 From: petechd Date: Thu, 20 May 2021 11:52:50 +0100 Subject: [PATCH 3/8] Remove census specific code from auth.go --- authentication/auth.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/authentication/auth.go b/authentication/auth.go index 2e39f2fc..bcf14085 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -389,25 +389,15 @@ func GenerateTokenFromDefaults(surveyURL string, accountServiceURL string, accou return token, "" } -// TransformSchemaParamsToName Returns a schema name from census schema parameters -// This function can be removed after census claims are removed. +// TransformSchemaParamsToName Returns a schema name from business schema parameters func TransformSchemaParamsToName(postValues url.Values) string { if postValues.Get("schema_name") != "" { return postValues["schema_name"][0] } - formTypeMap := map[string]string{ - "H": "household", - "I": "individual", - "C": "communal_establishment", - } - - regionCode := strings.Replace(postValues.Get("region_code"), "-", "_", -1) - regionCode = strings.ToLower(regionCode) - - survey := postValues.Get("survey") - formType := formTypeMap[postValues.Get("form_type")] - schemaName := fmt.Sprintf("%s_%s_%s", survey, formType, regionCode) + eqId := postValues.Get("eq_id") + formType := postValues.Get("form_type") + schemaName := fmt.Sprintf("%s_%s", eqId, formType) return schemaName } From 51bcd8538f95368b1e2ae489f7dfeaee6bebbfb8 Mon Sep 17 00:00:00 2001 From: petechd Date: Thu, 20 May 2021 11:58:57 +0100 Subject: [PATCH 4/8] Remove census functions from launch.html --- templates/launch.html | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/templates/launch.html b/templates/launch.html index 4569cb3f..6404ef6b 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -130,53 +130,10 @@

Runner Data

// uuidv4: from https://github.com/kelektiv/node-uuid !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.uuidv4=e()}}(function(){return function e(n,r,o){function t(f,u){if(!r[f]){if(!n[f]){var a="function"==typeof require&&require;if(!u&&a)return a(f,!0);if(i)return i(f,!0);var d=new Error("Cannot find module '"+f+"'");throw d.code="MODULE_NOT_FOUND",d}var p=r[f]={exports:{}};n[f][0].call(p.exports,function(e){var r=n[f][1][e];return t(r?r:e)},p,p.exports,e,n,r,o)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f>>((3&n)<<3)&255;return i}}},{}],3:[function(e,n,r){function o(e,n,r){var o=n&&r||0;"string"==typeof e&&(n="binary"===e?new Array(16):null,e=null),e=e||{};var f=e.random||(e.rng||t)();if(f[6]=15&f[6]|64,f[8]=63&f[8]|128,n)for(var u=0;u<16;++u)n[o+u]=f[u];return n||i(f)}var t=e("./lib/rng"),i=e("./lib/bytesToUuid");n.exports=o},{"./lib/bytesToUuid":1,"./lib/rng":2}]},{},[3])(3)}); - function clearCensusClaims() { - document.getElementById('census_claims').innerHTML = "" - } - - function includeCensusClaims(schema_name, is_census_test_schema = false) { - let surveyValue = "CENSUS" - let formTypeValue = "C" - let regionCodeValue = "GB-ENG" - - if (!is_census_test_schema) { - const matches = schema_name_census_regex.exec(schema_name) - surveyValue = matches[1].toUpperCase() - formTypeValue = form_types[matches[2]] - regionCodeValue = matches[3].toUpperCase().replace('_', '-') - } - - document.getElementById('census_claims').innerHTML = ` -
- - -
-
- - -
-
- - -
-
- - -
- ` - } - function loadMetadata() { document.getElementById("submit-btn").disabled = true; document.getElementById("flush-btn").disabled = true; - const schema_name = document.getElementById("schema_name").value - const is_census_test_schema = schema_name === "test_individual_response" - if (is_census_test_schema) { - includeCensusClaims(schema_name, is_census_test_schema) - } else { - clearCensusClaims() - } var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { From 9b828acd5e80dbabc7ff75239e8992010580ef45 Mon Sep 17 00:00:00 2001 From: petechd Date: Thu, 20 May 2021 12:02:59 +0100 Subject: [PATCH 5/8] Add eq_id default value --- authentication/auth.go | 1 + 1 file changed, 1 insertion(+) diff --git a/authentication/auth.go b/authentication/auth.go index bcf14085..6ea6c926 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -526,6 +526,7 @@ func GetDefaultValues() map[string]string { defaults["postcode"] = "PE12 4GH" defaults["display_address"] = "68 Abingdon Road, Goathill" defaults["country"] = "E" + defaults["eq_id"] = "mbs" return defaults } From 107e5417e7a762d5e0a5b58f7e4db68c965abdba Mon Sep 17 00:00:00 2001 From: petechd Date: Fri, 21 May 2021 09:10:40 +0100 Subject: [PATCH 6/8] Add business claims --- authentication/auth.go | 1 - templates/launch.html | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/authentication/auth.go b/authentication/auth.go index 6ea6c926..bcf14085 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -526,7 +526,6 @@ func GetDefaultValues() map[string]string { defaults["postcode"] = "PE12 4GH" defaults["display_address"] = "68 Abingdon Road, Goathill" defaults["country"] = "E" - defaults["eq_id"] = "mbs" return defaults } diff --git a/templates/launch.html b/templates/launch.html index 6404ef6b..13c3e786 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -33,7 +33,7 @@

Launch a survey

-
+

Survey Metadata

@@ -130,10 +130,37 @@

Runner Data

// uuidv4: from https://github.com/kelektiv/node-uuid !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.uuidv4=e()}}(function(){return function e(n,r,o){function t(f,u){if(!r[f]){if(!n[f]){var a="function"==typeof require&&require;if(!u&&a)return a(f,!0);if(i)return i(f,!0);var d=new Error("Cannot find module '"+f+"'");throw d.code="MODULE_NOT_FOUND",d}var p=r[f]={exports:{}};n[f][0].call(p.exports,function(e){var r=n[f][1][e];return t(r?r:e)},p,p.exports,e,n,r,o)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f>>((3&n)<<3)&255;return i}}},{}],3:[function(e,n,r){function o(e,n,r){var o=n&&r||0;"string"==typeof e&&(n="binary"===e?new Array(16):null,e=null),e=e||{};var f=e.random||(e.rng||t)();if(f[6]=15&f[6]|64,f[8]=63&f[8]|128,n)for(var u=0;u<16;++u)n[o+u]=f[u];return n||i(f)}var t=e("./lib/rng"),i=e("./lib/bytesToUuid");n.exports=o},{"./lib/bytesToUuid":1,"./lib/rng":2}]},{},[3])(3)}); + function clearBusinessClaims() { + document.getElementById('business_claims').innerHTML = "" + } + + function includeBusinessClaims(schema_name) { + let eqIdValue = schema_name.split('_')[0] + let formTypeValue = schema_name.split('_')[1] + + document.getElementById('business_claims').innerHTML = ` +
+ + +
+
+ + +
+ ` + } + function loadMetadata() { document.getElementById("submit-btn").disabled = true; document.getElementById("flush-btn").disabled = true; + const schema_name = document.getElementById("schema_name").value + + if (schema_name.startsWith('test_')) { + clearBusinessClaims() + } else { + includeBusinessClaims(schema_name) + } var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { From 3466c3c0f497e287abaae6257c9a40cba80cb1e1 Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 24 May 2021 12:05:34 +0100 Subject: [PATCH 7/8] Delete census code from generateClaims and restructure html --- authentication/auth.go | 3 +-- templates/launch.html | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/authentication/auth.go b/authentication/auth.go index bcf14085..c1a40829 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -143,8 +143,7 @@ func generateClaims(claimValues map[string][]string, launcherSchema surveys.Laun claims[key] = value } } - var isCensusTestSchema = len(claimValues["schema_name"]) > 0 && claimValues["schema_name"][0] == "test_individual_response" - if !isCensusTestSchema && (len(claimValues["survey"]) > 0 || len(claimValues["form_type"]) > 0 || len(claimValues["region_code"]) > 0) { + if len(claimValues["form_type"]) > 0 { log.Println("Deleting schema name from claims") delete(claims, "schema_name") } else { diff --git a/templates/launch.html b/templates/launch.html index 13c3e786..9ae39c63 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -139,12 +139,13 @@

Runner Data

let formTypeValue = schema_name.split('_')[1] document.getElementById('business_claims').innerHTML = ` +

Business Survey Metadata

- +
- +
` From 9fcbbb8206d0941d729eaaf35490e91d3aa0fab2 Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 24 May 2021 12:20:29 +0100 Subject: [PATCH 8/8] Add eq_id check in generateClaims --- authentication/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/auth.go b/authentication/auth.go index c1a40829..c8cd3ac7 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -143,7 +143,7 @@ func generateClaims(claimValues map[string][]string, launcherSchema surveys.Laun claims[key] = value } } - if len(claimValues["form_type"]) > 0 { + if len(claimValues["form_type"]) > 0 && len(claimValues["eq_id"]) > 0 { log.Println("Deleting schema name from claims") delete(claims, "schema_name") } else {