Skip to content

Commit

Permalink
return integrityUrl in Form manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Jan 3, 2025
1 parent 274a85a commit bf6acca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/formats/openrosa.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const formManifestTemplate = template(200, `<?xml version="1.0" encoding="UTF-8"
<filename>{{name}}</filename>
<hash>md5:{{openRosaHash}}</hash>
<downloadUrl>{{{domain}}}{{{basePath}}}/attachments/{{urlName}}</downloadUrl>
{{#integrityUrl}}
<integrityUrl>{{{integrityUrl}}}</integrityUrl>
{{/integrityUrl}}
</mediaFile>
{{/hasSource}}
{{/attachments}}
Expand All @@ -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
}))
}));

Expand Down
2 changes: 1 addition & 1 deletion lib/resources/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ describe('datasets and entities', () => {
<filename>goodone.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/goodone/integrity</integrityUrl>
</mediaFile>
</manifest>`);
}));
Expand Down Expand Up @@ -2066,6 +2067,7 @@ describe('datasets and entities', () => {
<filename>goodone.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/goodone/integrity</integrityUrl>
</mediaFile>
</manifest>`);
}));
Expand Down Expand Up @@ -2941,6 +2943,7 @@ describe('datasets and entities', () => {
<filename>people.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/people.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/people/integrity</integrityUrl>
</mediaFile>
</manifest>`);
});
Expand Down

0 comments on commit bf6acca

Please sign in to comment.