Skip to content

Commit

Permalink
Merge pull request #1311 from sadiqkhoja/features/789_submission_hist…
Browse files Browse the repository at this point in the history
…ory_with_delete_undelete

Add submissionId in delete and restore audit
  • Loading branch information
sadiqkhoja authored Dec 2, 2024
2 parents 57c4da5 + bcd1957 commit 3d86d4b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ const getForExport = (formId, instanceId, draft, options = QueryOptions.none) =>

const del = (submission) => ({ run }) =>
run(markDeleted(submission));
del.audit = (submission, form) => (log) => log('submission.delete', { acteeId: form.acteeId }, { instanceId: submission.instanceId });
del.audit = (submission, form) => (log) => log('submission.delete', { acteeId: form.acteeId }, { submissionId: submission.id, instanceId: submission.instanceId });

const restore = (submission) => ({ run }) =>
run(markUndeleted(submission));
restore.audit = (submission, form) => (log) => log('submission.restore', { acteeId: form.acteeId }, { instanceId: submission.instanceId });
restore.audit = (submission, form) => (log) => log('submission.restore', { acteeId: form.acteeId }, { submissionId: submission.id, instanceId: submission.instanceId });

////////////////////////////////////////////////////////////////////////////////
// PURGING SOFT-DELETED SUBMISSIONS
Expand Down
30 changes: 21 additions & 9 deletions test/integration/api/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3362,22 +3362,34 @@ one,h,/data/h,2000-01-01T00:06,2000-01-01T00:07,-5,-6,,ee,ff
.send(withSimpleIds('one', 'two'))
.set('Content-Type', 'text/xml')
.expect(200))
.then(() => asAlice.delete('/v1/projects/1/forms/simple/submissions/one')
.expect(200))
.then(() => asAlice.post('/v1/projects/1/forms/simple/submissions/one/restore')
.expect(200))
.then(() => oneFirst(sql`select id from submissions`))
.then((submissionId) => all(sql`SELECT id FROM submission_defs WHERE "submissionId" = ${submissionId} ORDER BY id desc`)
.then(map(o => o.id))
.then(submissionDefIds => asAlice.get('/v1/projects/1/forms/simple/submissions/one/audits')
.expect(200)
.then(({ body }) => {
body.length.should.equal(3);
body.length.should.equal(5);
for (const audit of body) audit.should.be.an.Audit();
body[0].action.should.equal('submission.update.version');
body[0].details.should.eql({ instanceId: 'two', submissionId, submissionDefId: submissionDefIds[0] });
body[1].action.should.equal('submission.update');
body[1].details.reviewState.should.equal('rejected');
body[1].details.submissionId.should.equal(submissionId);
should.exist(body[1].details.submissionDefId);
body[2].action.should.equal('submission.create');
body[2].details.should.eql({ instanceId: 'one', submissionId, submissionDefId: submissionDefIds[1] });
body[0].action.should.equal('submission.restore');
body[0].details.should.eql({ submissionId, instanceId: 'one' });

body[1].action.should.equal('submission.delete');
body[1].details.should.eql({ submissionId, instanceId: 'one' });

body[2].action.should.equal('submission.update.version');
body[2].details.should.eql({ instanceId: 'two', submissionId, submissionDefId: submissionDefIds[0] });

body[3].action.should.equal('submission.update');
body[3].details.reviewState.should.equal('rejected');
body[3].details.submissionId.should.equal(submissionId);
should.exist(body[3].details.submissionDefId);

body[4].action.should.equal('submission.create');
body[4].details.should.eql({ instanceId: 'one', submissionId, submissionDefId: submissionDefIds[1] });
}))))));

it('should not expand actor when not extended', testService((service) =>
Expand Down

0 comments on commit 3d86d4b

Please sign in to comment.