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

Distinguish User Data Field required for Web User or Mobile Worker #35218

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Jtang-1
Copy link
Contributor

@Jtang-1 Jtang-1 commented Oct 14, 2024

Product Description

When editing a User Field, checking "Required" will also display a dropdown with the selection "Web Users", "Mobile Workers" or "Both". When

  • "Web Users" is selected, that field is required only when editing a Web User or for Web User Invite.
  • "Mobile Workers" is selected, that field is required only when editing a Mobile Worker and creating a Mobile Worker.
  • "Both" is selected, that field is required in all cases.

Screen Shot 2024-10-17 at 11 10 00 AM

Technical Summary

USH-4867
Design Spec

Commits are fairly clean, can review commit by commit.

Feature Flag

no FF

Safety Assurance

Safety story

Tested locally and on staging. The blast radius is limited to Custom User Data.

Automated test coverage

Added tests

  • Field property containing lists are serialized upon form submission and cleaned data contains the expected list
  • Field model is serialized correctly
  • Form fields that should be required are set as required upon form creation _make_field
  • View helper function is_field_required to check if a field is required (taking into consideration required_for)
  • Filtering and getting Fields from CustomDataFieldsDefinition works

QA Plan

QA-7171

Migrations

  • The migrations in this code can be safely applied first independently of the code

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@dimagimon dimagimon added reindex/migration Reindex or migration will be required during or before deploy Risk: Medium Change affects files that have been flagged as medium risk. labels Oct 14, 2024
Copy link

sentry-io bot commented Oct 14, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: corehq/apps/custom_data_fields/edit_model.py

Function Unhandled Issue
page_context MultiValueDictKeyError: 'data_fields' /a/{domain}...
Event Count: 7
page_context MultiValueDictKeyError: 'data_fields' /a/{domain}...
Event Count: 2

Did you find this useful? React with a 👍 or 👎

@Jtang-1 Jtang-1 force-pushed the jt/user_data_field_targeted_require branch from 695131e to c5c7fd6 Compare October 15, 2024 19:02
…oncept and is consistent with model definition
…nce instead of the contents of the list.

So the intial value did not match to its corresponding option and was not set correclt on the select element dropdown.
This change finds the match and sets the intial value as the same reference as that on requiredForOptions so that the
<select> element will correctly identify the match
@Jtang-1 Jtang-1 force-pushed the jt/user_data_field_targeted_require branch from c5c7fd6 to 034792b Compare October 15, 2024 23:01
@dimagimon dimagimon added the Risk: High Change affects files that have been flagged as high risk. label Oct 15, 2024
@Jtang-1 Jtang-1 requested review from kaapstorm, orangejenny, a team, MartinRiese and minhaminha and removed request for a team and orangejenny October 16, 2024 22:13
@Jtang-1 Jtang-1 marked this pull request as ready for review October 17, 2024 18:37
@orangejenny
Copy link
Contributor

UI thought: What if this were a dropdown of "Mobile Workers", "Web Users", "both", or "neither"? That seems simpler to think about than a checkbox plus a dropdown.

user_fields_definitions = CustomDataFieldsDefinition.objects.filter(field_type=CUSTOM_USER_DATA_FIELD_TYPE)

for definition in user_fields_definitions:
Field.objects.filter(definition=definition).update(required_for=DEFAULT_REQUIRED_FOR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a change from current behavior? From skimming the ticket and design document, it sounds like right now fields are required for both mobile and web users. It sounds like mobile workers only is the desired default behavior, but are you certain this change won't affect existing projects in a way they don't expect?

Copy link
Contributor Author

@Jtang-1 Jtang-1 Oct 17, 2024

Choose a reason for hiding this comment

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

Yes it is a change in current behavior and you're correct that right now, fields are required for both mobile and web users. We discussed/are discussing it in this comment thread. The decision from that discussion thread was to migrate existing projects to have required fields apply to "mobile worker".

But you're right that it would be disruptive to change current behavior. So I think the better strategy would be to migrate such that required fields still apply to both web users and mobile workers. And then domains who do not want required fields applied to web users can configure it as such. I followed up in that comment thread to get Mruga's thoughts

@orangejenny
Copy link
Contributor

Skimmed and left a couple of comments, didn't review closely.

@Jtang-1
Copy link
Contributor Author

Jtang-1 commented Oct 17, 2024

I did consider including a "None" option in the dropdown and getting rid of the checkbox. But I'm assuming most fields are not going to be required so I think it reduces clutter to just have a checkbox and not unnecessarily display a bunch of dropdowns with text. Also, this same input template is used for other custom data fields so it would also be more consistent to use a checkbox for them all (rather than having only a dropdown here and a checkbox for the other ones)

@Jtang-1 Jtang-1 added awaiting QA QA in progress. Do not merge Open for review: do not merge A work in progress labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting QA QA in progress. Do not merge Open for review: do not merge A work in progress reindex/migration Reindex or migration will be required during or before deploy Risk: High Change affects files that have been flagged as high risk. Risk: Medium Change affects files that have been flagged as medium risk.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants