diff --git a/lib/model/query/audits.js b/lib/model/query/audits.js index f8e75b5bf..2aa47e0d0 100644 --- a/lib/model/query/audits.js +++ b/lib/model/query/audits.js @@ -36,7 +36,7 @@ const actionCondition = (action) => { // The backup action was logged by a backup script that has been removed. // Even though the script has been removed, the audit log entries it logged // have not, so we should continue to exclude those. - return sql`action not in ('entity.create', 'entity.bulk.create', 'entity.error', 'entity.update.version', 'entity.update.resolve', 'entity.delete', 'submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.reprocess', 'backup', 'analytics')`; + return sql`action not in ('entity.create', 'entity.bulk.create', 'entity.error', 'entity.update.version', 'entity.update.resolve', 'entity.delete', 'submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.reprocess', 'submission.delete', 'submission.restore', 'backup', 'analytics')`; else if (action === 'user') return sql`action in ('user.create', 'user.update', 'user.delete', 'user.assignment.create', 'user.assignment.delete', 'user.session.create')`; else if (action === 'field_key') @@ -48,7 +48,7 @@ const actionCondition = (action) => { else if (action === 'form') return sql`action in ('form.create', 'form.update', 'form.delete', 'form.restore', 'form.purge', 'form.attachment.update', 'form.submission.export', 'form.update.draft.set', 'form.update.draft.delete', 'form.update.publish')`; else if (action === 'submission') - return sql`action in ('submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.reprocess')`; + return sql`action in ('submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.reprocess', 'submission.delete', 'submission.restore', 'submission.purge')`; else if (action === 'dataset') return sql`action in ('dataset.create', 'dataset.update')`; else if (action === 'entity') diff --git a/lib/model/query/submissions.js b/lib/model/query/submissions.js index f61d4d6c9..2eaad7c5d 100644 --- a/lib/model/query/submissions.js +++ b/lib/model/query/submissions.js @@ -403,8 +403,7 @@ const getForExport = (formId, instanceId, draft, options = QueryOptions.none) => const del = (submission) => ({ run }) => run(markDeleted(submission)); - -del.audit = (submission, form) => (log) => log('submission.delete', submission.with({ acteeId: form.acteeId }), { instanceId: submission.instanceId }); +del.audit = (submission, form) => (log) => log('submission.delete', { acteeId: form.acteeId }, { instanceId: submission.instanceId }); const restore = (submission) => ({ run }) => run(markUndeleted(submission)); @@ -466,7 +465,7 @@ with redacted_audits as ( using forms where submissions."formId" = forms.id and ${_trashedFilter(force, projectId, xmlFormId, instanceId)} - returning submissions.* + returning 1 ) select count(*) from deleted_submissions`); }; diff --git a/test/integration/api/submissions.js b/test/integration/api/submissions.js index 2db6b0a96..7c6e056b7 100644 --- a/test/integration/api/submissions.js +++ b/test/integration/api/submissions.js @@ -1442,8 +1442,12 @@ describe('api: /forms/:id/submissions', () => { describe('/:instanceId RESTORE', () => { it('should reject if the submission has not been deleted', testService((service) => service.login('alice', (asAlice) => - asAlice.post('/v1/projects/1/forms/simple/submissions/one/restore') - .expect(404)))); + asAlice.post('/v1/projects/1/forms/simple/submissions') + .send(testData.instances.simple.one) + .set('Content-Type', 'application/xml') + .expect(200) + .then(() => asAlice.post('/v1/projects/1/forms/simple/submissions/one/restore') + .expect(404))))); it('should reject if the submission does not exist', testService((service) => service.login('alice', (asAlice) => diff --git a/test/integration/other/form-purging.js b/test/integration/other/form-purging.js index 41858bb91..464baad44 100644 --- a/test/integration/other/form-purging.js +++ b/test/integration/other/form-purging.js @@ -88,8 +88,7 @@ describe('query module form purge', () => { await asAlice.get('/v1/audits') .then(({ body }) => { - const acteeIds = body.filter((a) => a.action === 'form.purge').map(a => a.acteeId).sort(); - acteeIds.should.eql([simpleForm.acteeId, repeatForm.acteeId].sort()); + body.filter((a) => a.action === 'form.purge').map(a => a.acteeId).should.eqlInAnyOrder([simpleForm.acteeId, repeatForm.acteeId]); }); })); diff --git a/test/integration/other/submission-purging.js b/test/integration/other/submission-purging.js index f702e96d1..ce01222e8 100644 --- a/test/integration/other/submission-purging.js +++ b/test/integration/other/submission-purging.js @@ -94,11 +94,12 @@ describe('query module submission purge', () => { await run(sql`update submissions set "deletedAt" = '1999-1-1' where "deletedAt" is not null`); - await Submissions.purge(); + const purgeCount = await Submissions.purge(); + purgeCount.should.equal(1); const counts = await Promise.all([ oneFirst(sql`select count(*) from submissions`), - oneFirst(sql`select count(*) from submissions`) + oneFirst(sql`select count(*) from submission_defs`) ]); counts.should.eql([ 0, 0 ]); @@ -136,7 +137,7 @@ describe('query module submission purge', () => { // Remaining submissions not recently deleted const counts = await Promise.all([ oneFirst(sql`select count(*) from submissions`), - oneFirst(sql`select count(*) from submissions`) + oneFirst(sql`select count(*) from submission_defs`) ]); counts.should.eql([ 1, 1 ]); }));