Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Sep 17, 2024
1 parent 9eb00f4 commit 9dfc0ae
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/model/query/audits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
5 changes: 2 additions & 3 deletions lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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`);
};
Expand Down
8 changes: 6 additions & 2 deletions test/integration/api/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
3 changes: 1 addition & 2 deletions test/integration/other/form-purging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
}));

Expand Down
7 changes: 4 additions & 3 deletions test/integration/other/submission-purging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);
Expand Down Expand Up @@ -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 ]);
}));
Expand Down

0 comments on commit 9dfc0ae

Please sign in to comment.