Skip to content

Commit

Permalink
exclude draft subs from submission getdeleted query for restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Nov 26, 2024
1 parent fa37ed3 commit 90ab687
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const getDeleted = (projectId, formId, instanceId) => ({ maybeOne }) =>
and submissions."formId" = ${formId}
and submissions."instanceId" = ${instanceId}
and submissions."deletedAt" IS NOT NULL
and submissions."draft" = false
`)
.then(map(construct(Submission)));

Expand Down
39 changes: 39 additions & 0 deletions test/integration/api/forms/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,45 @@ describe('api: /projects/:id/forms (drafts)', () => {
fds.should.equal(2); // Old draft has now been deleted. Count also includes published and new draft.
}));

it('should not let soft-deleted draft submissions be undeleted', testService(async (service, { oneFirst, run }) => {

Check failure on line 1089 in test/integration/api/forms/draft.js

View workflow job for this annotation

GitHub Actions / standard-tests

'oneFirst' is defined but never used

Check failure on line 1089 in test/integration/api/forms/draft.js

View workflow job for this annotation

GitHub Actions / standard-tests

'run' is defined but never used
const asAlice = await service.login('alice');

// Create a draft and send in two submissions
// one submission (one) will also be send to the published form and deleted and restored
// another submission (two) will only be sent to the draft form
await asAlice.post('/v1/projects/1/forms/simple/draft')
.expect(200);
await asAlice.post('/v1/projects/1/forms/simple/draft/submissions')
.send(testData.instances.simple.one)
.set('Content-Type', 'text/xml')
.expect(200);
await asAlice.post('/v1/projects/1/forms/simple/draft/submissions')
.send(testData.instances.simple.two)
.set('Content-Type', 'text/xml')
.expect(200);

// Abandon the draft to delete the submissions
await asAlice.delete('/v1/projects/1/forms/simple/draft');

// Send the same instance id submission to the published form
await asAlice.post('/v1/projects/1/forms/simple/submissions')
.send(testData.instances.simple.one)
.set('Content-Type', 'text/xml')
.expect(200);

// delete the published sub 'one'
await asAlice.delete('/v1/projects/1/forms/simple/submissions/one')
.expect(200);

// Try to undelete submission 'one' (this should undelete the one sent to the published form)
await asAlice.post('/v1/projects/1/forms/simple/submissions/one/restore')
.expect(200);

// Try to undelete the submission 'two' that only exists as a draft
await asAlice.post('/v1/projects/1/forms/simple/submissions/two/restore')
.expect(404);
}));

describe('experimental - recovering deleted draft submissions', () => {
it('should work in the straight forward case of replacing active draft with previous draft and submissions', testService(async (service, { oneFirst, run, Submissions }) => {
const asAlice = await service.login('alice');
Expand Down

0 comments on commit 90ab687

Please sign in to comment.