From 486f26e22b6fe31f176a49ca23c67ec7fa0a9459 Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Tue, 31 Oct 2023 17:02:55 -0400 Subject: [PATCH 1/7] add new field to FormBase --- corehq/apps/app_manager/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/corehq/apps/app_manager/models.py b/corehq/apps/app_manager/models.py index 59da5bec0f99..c076d964f2d6 100644 --- a/corehq/apps/app_manager/models.py +++ b/corehq/apps/app_manager/models.py @@ -1042,6 +1042,7 @@ class FormBase(DocumentSchema): is_release_notes_form = BooleanProperty(default=False) enable_release_notes = BooleanProperty(default=False) session_endpoint_id = StringProperty(exclude_if_none=True) # See toggles.SESSION_ENDPOINTS + respect_relevancy = BooleanProperty(default=False, exclude_if_none=True) # computed datums IDs that are allowed in endpoints function_datum_endpoints = StringListProperty() From 63776c8b86618b222ef361082f9f8c6f3ee26317 Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Tue, 31 Oct 2023 17:05:05 -0400 Subject: [PATCH 2/7] add suite generation for respect relevancy property --- .../suite_xml/post_process/endpoints.py | 24 ++++++++++----- .../apps/app_manager/suite_xml/xml_models.py | 2 ++ .../tests/test_suite_session_endpoints.py | 30 +++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py index e47685efd87d..18fb7d393273 100644 --- a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py +++ b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py @@ -48,7 +48,8 @@ def update_suite(self): for form in module.get_suite_forms(): if form.session_endpoint_id: self.suite.endpoints.append(self._make_session_endpoint( - form.session_endpoint_id, module, form)) + form.session_endpoint_id, module, form, + respect_relevancy=getattr(form, 'respect_relevancy'))) elif module.session_endpoint_id: for form in module.get_suite_forms(): endpoint = next( @@ -57,7 +58,8 @@ def update_suite(self): self.suite.endpoints.append(self._make_session_endpoint( endpoint.session_endpoint_id, module, form)) - def _make_session_endpoint(self, endpoint_id, module, form=None, should_add_last_selection_datum=True): + def _make_session_endpoint(self, endpoint_id, module, form=None, should_add_last_selection_datum=True, + respect_relevancy=None): stack = Stack() children = self.get_frame_children(module, form) argument_ids = self.get_argument_ids(children, form, should_add_last_selection_datum) @@ -102,11 +104,19 @@ def get_child(child_id): else: arguments.append(Argument(id=arg_id)) - return SessionEndpoint( - id=endpoint_id, - arguments=arguments, - stack=stack, - ) + if respect_relevancy: + return SessionEndpoint( + id=endpoint_id, + arguments=arguments, + stack=stack, + respect_relevancy=respect_relevancy + ) + else: + return SessionEndpoint( + id=endpoint_id, + arguments=arguments, + stack=stack + ) def get_argument_ids(self, frame_children, form=None, should_add_last_selection_datum=True): diff --git a/corehq/apps/app_manager/suite_xml/xml_models.py b/corehq/apps/app_manager/suite_xml/xml_models.py index d36b19896a1c..bedb0bdbc652 100644 --- a/corehq/apps/app_manager/suite_xml/xml_models.py +++ b/corehq/apps/app_manager/suite_xml/xml_models.py @@ -536,6 +536,8 @@ class SessionEndpoint(IdNode): arguments = NodeListField('argument', Argument) stack = NodeField('stack', Stack) + respect_relevancy = BooleanField('@respect-relevancy', required=False) + class Assertion(XmlObject): ROOT_NAME = 'assert' diff --git a/corehq/apps/app_manager/tests/test_suite_session_endpoints.py b/corehq/apps/app_manager/tests/test_suite_session_endpoints.py index a6134b0d5b9f..09d0224a516d 100644 --- a/corehq/apps/app_manager/tests/test_suite_session_endpoints.py +++ b/corehq/apps/app_manager/tests/test_suite_session_endpoints.py @@ -627,6 +627,36 @@ def test_shadow_module(self): del self.factory.app.modules[0] + def test_session_endpoint_respect_relevancy_on_followup_form(self): + self.form.session_endpoint_id = 'my_form' + self.form.respect_relevancy = True + self.factory.form_requires_case(self.form, case_type=self.parent_case_type) + with patch('corehq.util.view_utils.get_url_base') as get_url_base_patch: + get_url_base_patch.return_value = 'https://www.example.com' + suite = self.factory.app.create_suite() + self.assertXmlPartialEqual( + """ + + + + + + + + + + + + + + + + + """, + suite, + "./endpoint", + ) + @patch_validate_xform() @patch_get_xform_resource_overrides() From 8d97887d9f0b669bd924eba80d3e0be9aebe57d5 Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Tue, 31 Oct 2023 17:06:57 -0400 Subject: [PATCH 3/7] create checkbox on form settings page and link to model split module and form endpoint settings to sepearate files --- .../partials/form_session_endpoint.html | 44 +++++++++++++++++++ .../partials/forms/form_tab_settings.html | 2 +- ...ints.html => module_session_endpoint.html} | 2 +- .../modules/module_view_settings.html | 2 +- corehq/apps/app_manager/views/forms.py | 3 ++ 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html rename corehq/apps/app_manager/templates/app_manager/partials/{session_endpoints.html => module_session_endpoint.html} (91%) diff --git a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html new file mode 100644 index 000000000000..65b938614883 --- /dev/null +++ b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html @@ -0,0 +1,44 @@ +{% load i18n %} +{% load hq_shared_tags %} + +
+ +
+ +
+
+
+ +

{{ form.name }} {{form.respect_relevancy}}

+
+ + +
+
diff --git a/corehq/apps/app_manager/templates/app_manager/partials/forms/form_tab_settings.html b/corehq/apps/app_manager/templates/app_manager/partials/forms/form_tab_settings.html index 565675e94d64..2ab63d09232f 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/forms/form_tab_settings.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/forms/form_tab_settings.html @@ -79,7 +79,7 @@ {% endif %} {% if session_endpoints_enabled %} - {% include "app_manager/partials/session_endpoints.html" with module_or_form=form %} + {% include "app_manager/partials/form_session_endpoint.html" with form=form %} {% include "app_manager/partials/function_datum_endpoints.html" with module_or_form=form %} {% endif %} diff --git a/corehq/apps/app_manager/templates/app_manager/partials/session_endpoints.html b/corehq/apps/app_manager/templates/app_manager/partials/module_session_endpoint.html similarity index 91% rename from corehq/apps/app_manager/templates/app_manager/partials/session_endpoints.html rename to corehq/apps/app_manager/templates/app_manager/partials/module_session_endpoint.html index b7d662db62ed..17aff1eb668b 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/session_endpoints.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/module_session_endpoint.html @@ -17,6 +17,6 @@ type="text" id="session_endpoint_id" name="session_endpoint_id" - value="{{ module_or_form.session_endpoint_id|default:'' }}" /> + value="{{ module.session_endpoint_id|default:'' }}" /> diff --git a/corehq/apps/app_manager/templates/app_manager/partials/modules/module_view_settings.html b/corehq/apps/app_manager/templates/app_manager/partials/modules/module_view_settings.html index 18352c50d820..8ee870e72e49 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/modules/module_view_settings.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/modules/module_view_settings.html @@ -255,7 +255,7 @@ {% endif %} {% if session_endpoints_enabled %} - {% include "app_manager/partials/session_endpoints.html" with module_or_form=module %} + {% include "app_manager/partials/module_session_endpoint.html" with module=module %} {% if not module.is_surveys %} {% include "app_manager/partials/case_list_session_endpoint.html" with module=module %} {% endif %} diff --git a/corehq/apps/app_manager/views/forms.py b/corehq/apps/app_manager/views/forms.py index fa2055af16f1..5b742325338b 100644 --- a/corehq/apps/app_manager/views/forms.py +++ b/corehq/apps/app_manager/views/forms.py @@ -455,6 +455,9 @@ def should_edit(attribute): raw_endpoint_id = request.POST['session_endpoint_id'] set_session_endpoint(form, raw_endpoint_id, app) + if should_edit('respect_relevancy'): + form.respect_relevancy = 'true' in request.POST.getlist('respect_relevancy') + if should_edit('function_datum_endpoints'): if request.POST['function_datum_endpoints']: form.function_datum_endpoints = request.POST['function_datum_endpoints'].replace(" ", "").split(",") From a81dda21150618d3c6a365110b5e1441afc134bf Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Wed, 1 Nov 2023 11:22:56 -0400 Subject: [PATCH 4/7] remove unnecessary p tag used for testing, add better positiong for checkbox --- .../templates/app_manager/partials/form_session_endpoint.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html index 65b938614883..2c74bdaf5539 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html @@ -28,7 +28,6 @@ data-content="{% blocktrans %}Turn this setting on to allow this endpoint to access hidden forms.{% endblocktrans %}"> -

{{ form.name }} {{form.respect_relevancy}}

From d56824d441df1daa9b8297e093ca3f6b728bdabd Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Thu, 2 Nov 2023 12:47:59 -0400 Subject: [PATCH 5/7] make respect_relevancy an inverse condition only include in suite if false --- corehq/apps/app_manager/models.py | 2 +- .../suite_xml/post_process/endpoints.py | 21 +++++++------------ .../partials/form_session_endpoint.html | 12 ++++++----- .../tests/test_suite_session_endpoints.py | 4 ++-- corehq/apps/app_manager/views/forms.py | 4 ++-- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/corehq/apps/app_manager/models.py b/corehq/apps/app_manager/models.py index c076d964f2d6..39f7be63bf13 100644 --- a/corehq/apps/app_manager/models.py +++ b/corehq/apps/app_manager/models.py @@ -1042,7 +1042,7 @@ class FormBase(DocumentSchema): is_release_notes_form = BooleanProperty(default=False) enable_release_notes = BooleanProperty(default=False) session_endpoint_id = StringProperty(exclude_if_none=True) # See toggles.SESSION_ENDPOINTS - respect_relevancy = BooleanProperty(default=False, exclude_if_none=True) + respect_relevancy = BooleanProperty(default=True, exclude_if_none=True) # computed datums IDs that are allowed in endpoints function_datum_endpoints = StringListProperty() diff --git a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py index 18fb7d393273..279f95d4c5e4 100644 --- a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py +++ b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py @@ -104,19 +104,14 @@ def get_child(child_id): else: arguments.append(Argument(id=arg_id)) - if respect_relevancy: - return SessionEndpoint( - id=endpoint_id, - arguments=arguments, - stack=stack, - respect_relevancy=respect_relevancy - ) - else: - return SessionEndpoint( - id=endpoint_id, - arguments=arguments, - stack=stack - ) + endpoint = SessionEndpoint( + id=endpoint_id, + arguments=arguments, + stack=stack + ) + if respect_relevancy is False: + endpoint.respect_relevancy = False + return endpoint def get_argument_ids(self, frame_children, form=None, should_add_last_selection_datum=True): diff --git a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html index 2c74bdaf5539..288c4581f7d5 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html @@ -28,17 +28,19 @@ data-content="{% blocktrans %}Turn this setting on to allow this endpoint to access hidden forms.{% endblocktrans %}"> -
- +
diff --git a/corehq/apps/app_manager/tests/test_suite_session_endpoints.py b/corehq/apps/app_manager/tests/test_suite_session_endpoints.py index 09d0224a516d..8caeccf55af4 100644 --- a/corehq/apps/app_manager/tests/test_suite_session_endpoints.py +++ b/corehq/apps/app_manager/tests/test_suite_session_endpoints.py @@ -629,7 +629,7 @@ def test_shadow_module(self): def test_session_endpoint_respect_relevancy_on_followup_form(self): self.form.session_endpoint_id = 'my_form' - self.form.respect_relevancy = True + self.form.respect_relevancy = False self.factory.form_requires_case(self.form, case_type=self.parent_case_type) with patch('corehq.util.view_utils.get_url_base') as get_url_base_patch: get_url_base_patch.return_value = 'https://www.example.com' @@ -637,7 +637,7 @@ def test_session_endpoint_respect_relevancy_on_followup_form(self): self.assertXmlPartialEqual( """ - + diff --git a/corehq/apps/app_manager/views/forms.py b/corehq/apps/app_manager/views/forms.py index 5b742325338b..c70373978995 100644 --- a/corehq/apps/app_manager/views/forms.py +++ b/corehq/apps/app_manager/views/forms.py @@ -455,8 +455,8 @@ def should_edit(attribute): raw_endpoint_id = request.POST['session_endpoint_id'] set_session_endpoint(form, raw_endpoint_id, app) - if should_edit('respect_relevancy'): - form.respect_relevancy = 'true' in request.POST.getlist('respect_relevancy') + if should_edit('access_hidden_forms'): + form.respect_relevancy = not ('true' in request.POST.getlist('access_hidden_forms')) if should_edit('function_datum_endpoints'): if request.POST['function_datum_endpoints']: From a1f325b1e8f64aab9c3d1c343c692bbae23f26df Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Thu, 2 Nov 2023 17:12:08 -0400 Subject: [PATCH 6/7] remove model field that causes problems saving --- corehq/apps/app_manager/models.py | 2 +- .../templates/app_manager/partials/form_session_endpoint.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/corehq/apps/app_manager/models.py b/corehq/apps/app_manager/models.py index 808a99996d14..393d171d0c22 100644 --- a/corehq/apps/app_manager/models.py +++ b/corehq/apps/app_manager/models.py @@ -1042,7 +1042,7 @@ class FormBase(DocumentSchema): is_release_notes_form = BooleanProperty(default=False) enable_release_notes = BooleanProperty(default=False) session_endpoint_id = StringProperty(exclude_if_none=True) # See toggles.SESSION_ENDPOINTS - respect_relevancy = BooleanProperty(default=True, exclude_if_none=True) + respect_relevancy = BooleanProperty(default=True) # computed datums IDs that are allowed in endpoints function_datum_endpoints = StringListProperty() diff --git a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html index 288c4581f7d5..c4ea50cdd4dc 100644 --- a/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html +++ b/corehq/apps/app_manager/templates/app_manager/partials/form_session_endpoint.html @@ -39,7 +39,7 @@ style="margin-top: 10px" {% comment %} respect_relevancy is an inverse condition of allowing access to hidden forms {% endcomment %} - {% if not form.respect_relevancy %} checked {% endif %} + {% if form.respect_relevancy is False %} checked {% endif %} /> From be99636c0977a334fe957285473e347856c334c2 Mon Sep 17 00:00:00 2001 From: AddisonDunn Date: Thu, 2 Nov 2023 17:13:34 -0400 Subject: [PATCH 7/7] add default value to getattr --- corehq/apps/app_manager/suite_xml/post_process/endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py index 279f95d4c5e4..be9b42322ecf 100644 --- a/corehq/apps/app_manager/suite_xml/post_process/endpoints.py +++ b/corehq/apps/app_manager/suite_xml/post_process/endpoints.py @@ -49,7 +49,7 @@ def update_suite(self): if form.session_endpoint_id: self.suite.endpoints.append(self._make_session_endpoint( form.session_endpoint_id, module, form, - respect_relevancy=getattr(form, 'respect_relevancy'))) + respect_relevancy=getattr(form, 'respect_relevancy', None))) elif module.session_endpoint_id: for form in module.get_suite_forms(): endpoint = next(