Skip to content

Commit 2f1bffc

Browse files
sadiqkhojaspwoodcock
authored andcommitted
Fixes: exclude entity.restore and entity.purge from nonverbose audits endpoint (getodk#1442)
* Fixes: exclude entity.restore and entity.purge from nonverbose audits endpoint * update API doc
1 parent 7d3bfee commit 2f1bffc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

docs/api.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ tags:
903903
* `entity.update.version` when an Entity is updated.
904904
* `entity.update.resolve` when an Entity conflict is resolved.
905905
* `entity.delete` when an Entity is deleted.
906+
* `entity.restore` when a deleted Entity is restored.
907+
* `entity.purge` when a deleted Entity is purged (ppermanently deleted).
906908
* `config.set` when a system configuration is set.
907909
* `analytics` when a Usage Report is attempted.
908910
* `blobs.s3.upload` when blobs are moved from the database to external storage.

lib/model/query/audits.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const actionCondition = (action) => {
3838
// The backup action was logged by a backup script that has been removed.
3939
// Even though the script has been removed, the audit log entries it logged
4040
// have not, so we should continue to exclude those.
41-
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.backlog.hold', 'submission.backlog.reprocess', 'submission.backlog.force', 'submission.delete', 'submission.restore', 'backup', 'analytics')`;
41+
return sql`action not in ('entity.create', 'entity.bulk.create', 'entity.error', 'entity.update.version', 'entity.update.resolve', 'entity.delete', 'entity.restore', 'entity.purge', 'submission.create', 'submission.update', 'submission.update.version', 'submission.attachment.update', 'submission.backlog.hold', 'submission.backlog.reprocess', 'submission.backlog.force', 'submission.delete', 'submission.restore', 'backup', 'analytics')`;
4242
else if (action === 'user')
4343
return sql`action in ('user.create', 'user.update', 'user.delete', 'user.assignment.create', 'user.assignment.delete', 'user.session.create')`;
4444
else if (action === 'field_key')
@@ -54,7 +54,7 @@ const actionCondition = (action) => {
5454
else if (action === 'dataset')
5555
return sql`action in ('dataset.create', 'dataset.update')`;
5656
else if (action === 'entity')
57-
return sql`action in ('entity.create', 'entity.bulk.create', 'entity.error', 'entity.update.version', 'entity.update.resolve', 'entity.delete')`;
57+
return sql`action in ('entity.create', 'entity.bulk.create', 'entity.error', 'entity.update.version', 'entity.update.resolve', 'entity.delete', 'entity.restore', 'entity.purge')`;
5858

5959
return sql`action=${action}`;
6060
};

test/integration/api/audits.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,20 @@ describe('/audits', () => {
406406
body.success.should.be.true();
407407
});
408408

409+
await asAlice.post('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc/restore')
410+
.expect(200);
411+
await asAlice.delete('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
412+
.expect(200);
413+
await container.Entities.purge(true);
414+
409415
await asAlice.get('/v1/audits?action=entity')
410416
.expect(200)
411417
.then(({ body }) => {
412-
body.length.should.equal(6);
418+
body.length.should.equal(9);
413419
body.map(a => a.action).should.eql([
420+
'entity.purge',
421+
'entity.delete',
422+
'entity.restore',
414423
'entity.delete',
415424
'entity.update.resolve',
416425
'entity.update.version',
@@ -614,6 +623,11 @@ describe('/audits', () => {
614623
.then(({ body }) => {
615624
body.success.should.be.true();
616625
});
626+
await asAlice.post('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc/restore')
627+
.expect(200);
628+
await asAlice.delete('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
629+
.expect(200);
630+
await container.Entities.purge(true);
617631
await asAlice.post('/v1/projects/1/datasets/people/entities')
618632
.send({
619633
source: {

0 commit comments

Comments
 (0)