diff --git a/lib/model/query/audits.js b/lib/model/query/audits.js index 3a4d75e2d..f8e75b5bf 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', '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', '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')`; + return sql`action in ('submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.reprocess')`; else if (action === 'dataset') return sql`action in ('dataset.create', 'dataset.update')`; else if (action === 'entity') @@ -112,7 +112,8 @@ ${extend|| sql` LEFT JOIN entity_defs AS current_entity_def ON current_entity_def."entityId" = entities.id AND current `} WHERE (audits.details->>'submissionId')::INTEGER = ${submissionId} - + -- suppress this one event that is used for offline entity ordering/processing + AND audits.action != 'submission.reprocess' ORDER BY audits."loggedAt" DESC, audits.id DESC ${page(options)}`); diff --git a/test/integration/api/audits.js b/test/integration/api/audits.js index cfb4421d8..01496bcf4 100644 --- a/test/integration/api/audits.js +++ b/test/integration/api/audits.js @@ -1,5 +1,6 @@ const appRoot = require('app-root-path'); const should = require('should'); +const uuid = require('uuid').v4; const { sql } = require('slonik'); const { plain } = require('../../util/util'); const { testService } = require('../setup'); @@ -644,6 +645,49 @@ describe('/audits', () => { }); })); + it('should filter out offline entity submission reprocessing events given action=nonverbose', testService(async (service, container) => { + const asAlice = await service.login('alice'); + + await asAlice.post('/v1/projects/1/forms?publish=true') + .send(testData.forms.offlineEntity) + .expect(200); + + const branchId = uuid(); + + // second submission in a branch will get held to wait for first in branch + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.two + .replace('create="1"', 'update="1"') + .replace('branchId=""', `branchId="${branchId}"`) + .replace('two', 'two-update') + .replace('baseVersion=""', 'baseVersion="1"') + .replace('new', 'checked in') + ) + .set('Content-Type', 'application/xml') + .expect(200); + + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.two + .replace('branchId=""', `branchId="${branchId}"`) + ) + .set('Content-Type', 'application/xml') + .expect(200); + + await exhaust(container); + + await asAlice.get('/v1/audits?action=nonverbose') + .expect(200) + .then(({ body }) => { + body.length.should.equal(4); + body.map(a => a.action).should.eql([ + 'form.update.publish', + 'dataset.create', + 'form.create', + 'user.session.create' + ]); + }); + })); + it('should log and return notes if given', testService((service) => service.login('alice', (asAlice) => asAlice.post('/v1/projects/1/forms?publish=true') diff --git a/test/integration/api/offline-entities.js b/test/integration/api/offline-entities.js index df805c833..6d201a7c3 100644 --- a/test/integration/api/offline-entities.js +++ b/test/integration/api/offline-entities.js @@ -486,12 +486,6 @@ describe('Offline Entities', () => { await exhaust(container); - await asAlice.get('/v1/projects/1/forms/offlineEntity/submissions/one-update2/audits') - .expect(200) - .then(({ body }) => { - body[1].action.should.equal('submission.reprocess'); - }); - await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc') .expect(200) .then(({ body }) => { @@ -608,6 +602,42 @@ describe('Offline Entities', () => { body.currentVersion.branchBaseVersion.should.equal(2); }); })); + + it('should not include submission.reprocess event in audit log of held submission', testOfflineEntities(async (service, container) => { + const asAlice = await service.login('alice'); + const branchId = uuid(); + + // Send second update in first + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.one + .replace('branchId=""', `branchId="${branchId}"`) + .replace('one', 'one-update1') + .replace('baseVersion="1"', 'baseVersion="2"') + .replace('arrived', 'working') + ) + .set('Content-Type', 'application/xml') + .expect(200); + + // Send first update in + await asAlice.post('/v1/projects/1/forms/offlineEntity/submissions') + .send(testData.instances.offlineEntity.one + .replace('branchId=""', `branchId="${branchId}"`) + ) + .set('Content-Type', 'application/xml') + .expect(200); + + await exhaust(container); + + await asAlice.get('/v1/projects/1/forms/offlineEntity/submissions/one-update1/audits') + .expect(200) + .then(({ body }) => { + body.length.should.equal(2); + body.map(a => a.action).should.eql([ + 'entity.update.version', + 'submission.create' + ]); + }); + })); }); describe('reprocessing submissions when toggling approvalRequired dataset flag', () => {