From bf6acca49902e365c2ef90f56f756acde23b4d94 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Mon, 23 Dec 2024 18:56:39 -0500 Subject: [PATCH] return integrityUrl in Form manifest --- lib/formats/openrosa.js | 8 +++++++- lib/resources/forms.js | 2 +- test/integration/api/datasets.js | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/formats/openrosa.js b/lib/formats/openrosa.js index f3d416c98..06339bca6 100644 --- a/lib/formats/openrosa.js +++ b/lib/formats/openrosa.js @@ -66,6 +66,9 @@ const formManifestTemplate = template(200, `{{name}} md5:{{openRosaHash}} {{{domain}}}{{{basePath}}}/attachments/{{urlName}} + {{#integrityUrl}} + {{{integrityUrl}}} + {{/integrityUrl}} {{/hasSource}} {{/attachments}} @@ -77,7 +80,10 @@ const formManifest = (data) => formManifestTemplate(mergeRight(data, { attachment.with({ hasSource: attachment.blobId || attachment.datasetId, urlName: encodeURIComponent(attachment.name), - isDataset: attachment.datasetId != null + isDataset: attachment.datasetId != null, + integrityUrl: attachment.datasetId ? + `${data.domain}${data.projectPath}/datasets/${encodeURIComponent(attachment.name.replace(/\.[^/.]+$/, ''))}/integrity` + : null })) })); diff --git a/lib/resources/forms.js b/lib/resources/forms.js index 15cf8f585..ac7a2be25 100644 --- a/lib/resources/forms.js +++ b/lib/resources/forms.js @@ -293,7 +293,7 @@ module.exports = (service, endpoint) => { .then((form) => canReadForm(auth, form)) .then((form) => FormAttachments.getAllByFormDefIdForOpenRosa(form.def.id) .then((attachments) => - formManifest({ attachments, basePath: path.resolve(originalUrl, '..'), domain: env.domain }))))); + formManifest({ attachments, basePath: path.resolve(originalUrl, '..'), domain: env.domain, projectPath: originalUrl.replace(/\/forms\/([^/]+)\/manifest/, '') }))))); //////////////////////////////////////// // READ-ONLY ATTACHMENT ENDPOINTS diff --git a/test/integration/api/datasets.js b/test/integration/api/datasets.js index ccaadebf5..36be9d2f0 100644 --- a/test/integration/api/datasets.js +++ b/test/integration/api/datasets.js @@ -1982,6 +1982,7 @@ describe('datasets and entities', () => { goodone.csv md5:${etag.replace(/"/g, '')} ${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv + ${domain}/v1/projects/1/datasets/goodone/integrity `); })); @@ -2066,6 +2067,7 @@ describe('datasets and entities', () => { goodone.csv md5:${etag.replace(/"/g, '')} ${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv + ${domain}/v1/projects/1/datasets/goodone/integrity `); })); @@ -2941,6 +2943,7 @@ describe('datasets and entities', () => { people.csv md5:${etag.replace(/"/g, '')} ${domain}/v1/projects/1/forms/withAttachments/attachments/people.csv + ${domain}/v1/projects/1/datasets/people/integrity `); });