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

Remove use of conditional publish from Forms.createNew #1143

Merged
merged 10 commits into from May 18, 2024

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented May 10, 2024

Closes #1136

This PR consolidates Form publishing in one place, because Dataset publishing is tied to Form publishing. There were three different places to possibly publish a Dataset (creating a new form, updating a form, just publishing a form) and it was too hard to think about which Form scenario led to which Dataset scenario.


As of 5/10/24:

So far, I've removed publish=true from Forms.createNew(). Any time creating a new form was also going to publish the form, the Forms.publish() is now called separately.

One downside is that those lines of code aren't as cute and concise anymore. This only happened in one resource, in a test fixture, and in some tests.

Another downside is that the enketo test mock had a way to put it into an erroneous state for the next request, but a certain form POST request will trigger two enketo requests behind the scenes. I mucked with the enketo test mock to require you to remove the error state, but it's kind of ugly and required modifying multiple tests.

As of 5/14/24:

I decided that keeping publish=true in Forms.createVersion() had utility. There is one rare situation with encrypting existing forms where it really helps to publish concurrently, e.g. when there is both a published version and draft version of a form, and both active versions need to be encrypted. Because this has nothing to do with Datasets, Forms.createVersion does not have code to publish a dataset. I tried to clarify this with comments, too.

I also trie to make Forms.createNew() and Forms.createVersion() more similar. There are some things they both do (parse the form XML to get form fields and dataset info, insert form fields, insert attachments, do enketo things) and some things that are special (comparing against previous schemas for updated forms).

Checklist

  • I think I want to move enketo draft creation from _createNewDef to createVersion
  • improve enketo test infrastructure

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/model/query/forms.js Outdated Show resolved Hide resolved
test/util/enketo.js Outdated Show resolved Hide resolved
@ktuite ktuite force-pushed the ktuite/refactor_form_flow branch from a864f2f to 5e95823 Compare May 10, 2024 21:01
@ktuite ktuite marked this pull request as ready for review May 15, 2024 23:22
Copy link
Member Author

@ktuite ktuite left a comment

Choose a reason for hiding this comment

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

Try this to add reset() to global.enketo?

const reset = () => {
  if (global.enketo === undefined) global.enketo = { reset };
  Object.assign(global.enketo, defaults);
  cancelToken += 1;
};

lib/model/query/forms.js Outdated Show resolved Hide resolved
lib/model/query/forms.js Outdated Show resolved Hide resolved
lib/model/query/forms.js Show resolved Hide resolved
lib/model/query/forms.js Show resolved Hide resolved
test/integration/api/audits.js Outdated Show resolved Hide resolved
test/integration/api/forms/draft.js Outdated Show resolved Hide resolved
test/integration/api/forms/draft.js Outdated Show resolved Hide resolved
test/integration/api/forms/draft.js Outdated Show resolved Hide resolved
test/integration/api/forms/draft.js Outdated Show resolved Hide resolved
test/integration/api/forms/forms.js Outdated Show resolved Hide resolved
test/integration/api/forms/forms.js Outdated Show resolved Hide resolved
@ktuite ktuite merged commit 30b76db into master May 18, 2024
5 checks passed
@ktuite ktuite deleted the ktuite/refactor_form_flow branch May 18, 2024 00:08
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.

Streamline Form creation/update/publish paths to better fit with Entities
2 participants