diff --git a/authentication/auth.go b/authentication/auth.go
index 6b648543..8d47b2f6 100644
--- a/authentication/auth.go
+++ b/authentication/auth.go
@@ -173,6 +173,12 @@ func generateClaimsV2(claimValues map[string][]string, schema QuestionnaireSchem
claims["tx_id"] = TxID.String()
claims["version"] = "v2"
+ // always send survey_id for business/test surveys unless it's already in survey metadata
+ _, ok := claimValues["survey_id"]
+ if !ok && !isSocialSurvey(schema.SurveyType) {
+ claimValues["survey_id"] = []string{schema.SurveyId}
+ }
+
surveyMetadata := make(map[string]interface{})
data := make(map[string]interface{})
diff --git a/launch.go b/launch.go
index e4eb2476..612134ff 100644
--- a/launch.go
+++ b/launch.go
@@ -168,7 +168,7 @@ func redirectURL(w http.ResponseWriter, r *http.Request) {
} else if launchVersion != "" {
http.Redirect(w, r, hostURL+"/session?token="+token, 301)
} else {
- http.Error(w,"Invalid Action", 500)
+ http.Error(w, "Invalid Action", 500)
}
}
diff --git a/static/javascript/launch.js b/static/javascript/launch.js
index 501c711d..be9a55e2 100644
--- a/static/javascript/launch.js
+++ b/static/javascript/launch.js
@@ -139,6 +139,9 @@
// store fetch so it only needs to be re-done if the survey changes
let supplementaryDataSets = null;
+// We always need survey_id from top-level schema metadata for SDS retrieval
+let schemaSurveyId = null;
+
function clearSurveyMetadataFields() {
document.querySelector("#survey_metadata_fields").innerHTML = "";
showSupplementaryData(false);
@@ -386,14 +389,31 @@ function showCIRMetdata(cirInstrumentId, cirSchema) {
}
function updateSDSDropdown() {
- const surveyId = document.getElementById("survey_id")?.value;
+ const surveyId = schemaSurveyId;
const periodId = document.getElementById("period_id")?.value;
+
+ const supplementaryDataSection = document.querySelector(
+ "#supplementary_data",
+ );
+ const sdsDatasetIdElement = document.querySelector("#sds_dataset_id");
+
loadSDSDatasetMetadata(surveyId, periodId)
.then((sds_metadata_response) => {
if (sds_metadata_response?.length) {
+ document.querySelector("#supplementary_data").innerHTML = "";
supplementaryDataSets = sds_metadata_response;
showSupplementaryData(true);
showSubmitFlushButtons(true);
+
+ if (
+ !document
+ .querySelector("#survey_metadata")
+ .contains(sdsDatasetIdElement)
+ ) {
+ // add sds_dataset_id field into the SDS metadata section if not already in survey metadata
+ supplementaryDataSection.innerHTML = `
${getLabelFor("sds_dataset_id")}
`;
+ }
+
document.querySelector("#sds_dataset_id").innerHTML =
sds_metadata_response
.map(
@@ -428,6 +448,9 @@ function loadSchemaMetadata(schemaName, schemaUrl, cirInstrumentId) {
document.querySelector("#survey_metadata").innerHTML = "";
document.querySelector("#survey_metadata").innerHTML = "";
+ // We always need survey_id from top-level schema metadata for SDS retrieval
+ schemaSurveyId = schema_response.survey_id;
+
if (schema_response.metadata.length > 0) {
document.querySelector("#survey_metadata").innerHTML =
schema_response.metadata
@@ -483,22 +506,30 @@ function loadSupplementaryDataInfo() {
const selectedDataset = supplementaryDataSets?.find(
(d) => d["dataset_id"] === selectedDatasetId,
);
- if (selectedDataset) {
- const sdsDatasetMetadataKeys = [
- "title",
- "sds_schema_version",
- "total_reporting_units",
- "schema_version",
- "sds_dataset_version",
- ];
-
- document.querySelector("#supplementary_data").innerHTML =
- sdsDatasetMetadataKeys
- .map(
- (key) =>
- `${getLabelFor(key)}${getInputField(key, "text", selectedDataset[key], true)}
`,
- )
- .join("");
+
+ if (!selectedDataset) {
+ return;
+ }
+
+ const sdsDatasetMetadataKeys = [
+ "title",
+ "total_reporting_units",
+ "schema_version",
+ "sds_dataset_version",
+ ];
+
+ const sdsMetadataSection = document.querySelector("#supplementary_data");
+ const sdsMetadataField = (key) =>
+ `${getLabelFor(key)}${getInputField(key, "text", selectedDataset[key], true)}
`;
+
+ if (sdsMetadataSection.contains(document.querySelector("#sds_dataset_id"))) {
+ sdsMetadataSection.innerHTML += sdsDatasetMetadataKeys
+ .map(sdsMetadataField)
+ .join("");
+ } else {
+ sdsMetadataSection.innerHTML = sdsDatasetMetadataKeys
+ .map(sdsMetadataField)
+ .join("");
}
}
diff --git a/surveys/surveys.go b/surveys/surveys.go
index 9d6e839b..8c6f776d 100644
--- a/surveys/surveys.go
+++ b/surveys/surveys.go
@@ -44,7 +44,6 @@ type DatasetMetadata struct {
SurveyID string `json:"survey_id"`
PeriodID string `json:"period_id"`
Title string `json:"title"`
- SdsSchemaVersion int `json:"sds_schema_version"`
SdsPublishedAt string `json:"sds_published_at"`
TotalReportingUnits int `json:"total_reporting_units"`
SchemaVersion string `json:"schema_version"`
@@ -253,6 +252,7 @@ func GetSupplementaryDataSets(surveyId string, periodId string) ([]DatasetMetada
log.Printf("SDS API Base URL: %s", hostURL)
url := fmt.Sprintf("%s/v1/dataset_metadata?survey_id=%s&period_id=%s", hostURL, surveyId, periodId)
+ log.Printf("Getting SDS metadata: %s", url)
resp, err := client.Get(url)
if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 404) {
diff --git a/templates/launch.html b/templates/launch.html
index dfca1a42..e0f2f07f 100644
--- a/templates/launch.html
+++ b/templates/launch.html
@@ -1,36 +1,41 @@
{{ define "title" }}Launch a Survey{{ end }}
{{ define "body" }}
-Launch a survey
-
+
-{{ end }}
\ No newline at end of file
+{{ end }}