Fix for issue #355: Don't update form name from drafts if published version exists #357
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses issue #355 and updating form titles at the right times in the work flow.
Expected behavior, for which there are now tests:
This PR has gone through a couple phases:
Phase 1: Parse form name from FormDef XML on publish
First, I set up some checks in the draft upload part of the code so the new title will only get applied from a draft to the overall form if there is no published versions.
For transferring the title from the form from a draft on publish, I first tried an approach of reading the title directly from the form def xml. It had to wait for that xml to get loaded and parsed, so I don't know if it's a great approach (but also it's ok if publish is a little slow). It also had some clunky async/await code that seemed a little fragile, so I moved on to the next phase.
Phase 2: Add name to FormDef
Since each form XML definition has a title (or null title) that can change with each version, it makes a lot of sense to store that name here. (In the XML, the form name is called title, but everywhere in the code, including the database column name, this field is called name for consistency.)
I made a migration that adds the name column and backfills it with title information read from each FormDef xml.
I then use that FormDef.name to update the Form.name at the right places in the code.
Phase 3: Remove Form.name and just use the appropriate FormDef.name (not reflected in this PR yet)
Copying over the form name is confusing and redundant and in an effort to normalize the data, I'm working on removing Form.name and using the appropriate FormDef.name, since the form_def table is joined in any query about forms already.