Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover deleted draft submissions by soft-deleting them when updating the form draft #1299

Merged
merged 10 commits into from
Nov 26, 2024

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented Nov 16, 2024

Closes getodk/central#749

WIP while adding more tests and thinking about encrypted forms.

What has been done to verify that this works as intended?

Why is this the best possible solution? Were any other approaches considered?

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

lib/resources/forms.js Show resolved Hide resolved
@@ -137,7 +137,7 @@ module.exports = (service, endpoint) => {
: getPartial(Forms, request, project, Keys)))
.then((partial) => Promise.all([
Forms.createVersion(partial, form, false),
Submissions.clearDraftSubmissions(form.id)
Submissions.softDeleteDraftSubmissions(form.id)
]))
.then(() => Forms.clearUnneededDrafts(form))) // remove drafts made obsolete by new draft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this endpoint will no longer result in a new form draft that's ready to be purged, I think we can remove this line. It'd be a nice way to simplify the endpoint. I also think it'd make things clearer if there was only one thing that called clearUnneededDrafts() (namely, the purge task).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible reason to leave it here is when there are no submissions, the draft def can be cleaned up right away. There are some tests in "purging form fields of unneeded drafts" (in api: /projects/:id/forms (drafts)) that are checking for these defs to be purged immediately. I could change or remove those tests, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, interesting. No strong feelings, either way!

lib/model/query/submissions.js Outdated Show resolved Hide resolved
@ktuite
Copy link
Member Author

ktuite commented Nov 21, 2024

I've added tests for the 4 main scenarios in the issue, and I've also added some tests showing, experimentally, what it would be like to bring some of these deleted draft submissions back. It gets a little complicated depending on the scenario.

I also had to change the DB submission uniqueness constraint to allow for draft submissions that have been deleted to be able to reuse instance IDs. I am not 100% confident on the uniqueness constraint AND the trigger that exists to check instance ID uniqueness.

@ktuite ktuite force-pushed the ktuite/recover_deleted_draft_forms branch from ac2552a to 9dd22ac Compare November 25, 2024 22:41
lib/resources/forms.js Show resolved Hide resolved
.then(({ body }) => {
body.length.should.equal(2);
});
}));
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when currentDefId is the same as draftDefId?

@ktuite ktuite force-pushed the ktuite/recover_deleted_draft_forms branch from 90ab687 to 2e76ed0 Compare November 26, 2024 19:05
@ktuite ktuite merged commit 13b29c1 into master Nov 26, 2024
7 checks passed
@ktuite ktuite deleted the ktuite/recover_deleted_draft_forms branch November 26, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore options for recovering deleted draft submissions
2 participants