Skip to content

Commit

Permalink
Add initial user data for invites in page_context intead of shared ge…
Browse files Browse the repository at this point in the history
…t_field_page_context
  • Loading branch information
minhaminha committed Dec 19, 2024
1 parent 1bee3fc commit 64a805f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 9 additions & 2 deletions corehq/apps/users/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from corehq.apps.cloudcare.dbaccessors import get_cloudcare_apps, get_application_access_for_domain
from corehq.apps.custom_data_fields.edit_entity import CustomDataEditor
from corehq.apps.custom_data_fields.models import CustomDataFieldsProfile, CustomDataFieldsDefinition
from corehq.apps.custom_data_fields.models import CustomDataFieldsProfile, CustomDataFieldsDefinition, PROFILE_SLUG
from corehq.apps.registry.utils import get_data_registry_dropdown_options
from corehq.apps.reports.models import TableauVisualization, TableauUser
from corehq.apps.sso.models import IdentityProvider
Expand Down Expand Up @@ -1204,10 +1204,17 @@ def request_id(self):

@property
def page_context(self):
initial_values = {}
if self.invitation:
initial_values = {f.slug: self.invitation.custom_user_data.get(f.slug)
for f in self.custom_data.fields}
if self.invitation.profile:
initial_values[PROFILE_SLUG] = self.invitation.profile.id
ctx = {
'registration_form': self.invite_web_user_form,
'user_data': initial_values,
**self.custom_data.field_view.get_field_page_context(
self.domain, self.request.couch_user, self.custom_data, None, self.invitation
self.domain, self.request.couch_user, self.custom_data, None
)
}
return ctx
Expand Down
8 changes: 1 addition & 7 deletions corehq/apps/users/views/mobile/custom_data_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,14 @@ def get_displayable_profiles_and_edit_permission(cls, original_profile_id, domai

@classmethod
def get_field_page_context(cls, domain, couch_user, custom_data_editor: CustomDataEditor,
original_profile_id=None, invitation=None):
original_profile_id=None):
profiles, can_edit_original_profile = (
cls.get_displayable_profiles_and_edit_permission(
original_profile_id, domain, couch_user
)
)
serialized_profiles = [p.to_json() for p in profiles]

initial_values = {}
if invitation:
initial_values = {f.slug: invitation.custom_user_data.get(f.slug) for f in custom_data_editor.fields}
if invitation.profile:
initial_values[PROFILE_SLUG] = invitation.profile.id
return {
'can_edit_original_profile': can_edit_original_profile,
'custom_fields_slugs': [f.slug for f in custom_data_editor.fields],
Expand All @@ -123,7 +118,6 @@ def get_field_page_context(cls, domain, couch_user, custom_data_editor: CustomDa
],
'custom_fields_profiles': sorted(serialized_profiles, key=lambda x: x['name'].lower()),
'custom_fields_profile_slug': PROFILE_SLUG,
'user_data': initial_values,
}

@classmethod
Expand Down

0 comments on commit 64a805f

Please sign in to comment.