-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add Custom Data to Web User Invite #35124
Conversation
- Manually add a prefix to custom data fields for consistency with the `CustomDataEditor` form since all fields for that form have the prefix applied. This is will later be relevant for populating post data for disabled fields
When a field is disabled, it is not included in the form post data. This manually adds the field data back in
58d6529
to
e0fc01e
Compare
corehq/toggles/__init__.py
Outdated
@@ -2528,6 +2528,13 @@ def _commtrackify(domain_name, toggle_is_enabled): | |||
namespaces=[NAMESPACE_DOMAIN] | |||
) | |||
|
|||
WEB_USER_INVITE_ADDITIONAL_FIELDS = StaticToggle( | |||
'web_user_invite_additional_fields', | |||
'Enable additional fields in web user invite form for enhanced user details', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a "USH:" in front or is the automatically GAed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should 63273ea
corehq/apps/users/models.py
Outdated
if assigned_location_ids is None: | ||
assigned_location_ids = [] | ||
if custom_user_data is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? It seems like the check on line 572 would take care of this and I don's see custom_user_data used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, that's not needed. 8405864
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May have to read through again but looks good so far.
self.request = kwargs.get('request') | ||
super(AdminInvitesUserForm, self).__init__(domain=domain, data=data, **kwargs) | ||
self.can_edit_tableau_config = can_edit_tableau_config | ||
domain_obj = Domain.get_by_name(domain) | ||
self.fields['role'].choices = [('', _("Select a role"))] + role_choices | ||
if domain_obj: | ||
if domain_has_privilege(domain_obj.name, privileges.APP_USER_PROFILES): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be missing something but why is this FF not being used anymore? Is it effectively putting all this behind the new flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if domain_has_privilege(domain_obj.name, privileges.APP_USER_PROFILES) and profile: | ||
user_data = self.get_user_data(domain_obj.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does still require the domain privilege check for profiles and I believe it does do the check. Or maybe i'm misunderstanding your comment
… needs to be manually removed for conditional check
… the prefix within the name as defined by the user
bump for review |
@@ -584,13 +584,12 @@ def __init__(self, data=None, excluded_emails=None, is_add_user=None, | |||
), | |||
) | |||
|
|||
def clean_profile(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this not used anywhere else? I don't see any renaming where it is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clean_<fieldname>()
method is a hook for performing custom validation or any cleaning that is specific to that particular attribute on a specific field in a Django form. Here, the field containing the profile will actually have the field name <prefix>_profile
so clean_profile
won't work. So I moved the cleaning to the general clean()
and handle it via _validate_profile()
Product Description
Allows the user to define "user data" when creating a web user invite.
Technical Summary
USH-4895
Editing custom user data uses the
CustomDataEditor
class which generates the profile and user data fields forCustomDataForm
. The need here is very similar from the form UI side. However, it does not require populating existing user data.In order to reuse the
CustomDataForm
, I initialized an instance ofCustomDataEditor
which initializes the form. Then this instance ofCustomDataEditor
is injected intoAdminInvitesUserForm
. The fields and fieldsets created as part ofCustomDataForm
is then pulled out to create the field and fieldsets forAdminInvitesUserForm
. One issue faced is thatCustomDataForm
applies a form level defined prefix for each field but this prefix is applied only upon rendering the form. But since we are not using that form directly and are only extracting the fields, adding the prefix needs to be manually handled inAdminInvitesUserForm
.Additionally, when a user data field is defined and populated by the profile, the field is disabled. Because of this, posted data will not include data for this field.
CustomDataForm
already handles that and adds profile related fields to the post data.AdminInvitesUserForm
takes advantage of that by accessing post data viaself.custom_data.form.data
.Feature Flag
New feature flag:
WEB_USER_INVITE_ADDITIONAL_FIELDS
Safety Assurance
Safety story
Locally tested and both backend and frontend changes are gated behind a FF which limits the blast radius.
Automated test coverage
No automated test
QA Plan
QA-7109
Rollback instructions
Labels & Review