Skip to content

Commit

Permalink
Merge pull request #33689 from dimagi/ad/endpoints-access-to-hidden-f…
Browse files Browse the repository at this point in the history
…orms

Allow endpoints access to hidden forms
  • Loading branch information
AddisonDunn authored Nov 9, 2023
2 parents 3d6f454 + be99636 commit e335dcf
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 7 deletions.
1 change: 1 addition & 0 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,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)

# computed datums IDs that are allowed in endpoints
function_datum_endpoints = StringListProperty()
Expand Down
13 changes: 9 additions & 4 deletions corehq/apps/app_manager/suite_xml/post_process/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', None)))
elif module.session_endpoint_id:
for form in module.get_suite_forms():
endpoint = next(
Expand All @@ -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)
Expand Down Expand Up @@ -102,11 +104,14 @@ def get_child(child_id):
else:
arguments.append(Argument(id=arg_id))

return SessionEndpoint(
endpoint = SessionEndpoint(
id=endpoint_id,
arguments=arguments,
stack=stack,
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):

Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/app_manager/suite_xml/xml_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% load i18n %}
{% load hq_shared_tags %}

<div class="form-group">
<label class="control-label {% css_label_class %}">
{% trans 'Session Endpoint ID' %}
<span class="hq-help-template"
data-title="{% trans 'Session Endpoint ID' %}"
data-content="{% blocktrans %}A session endpoint ID allows Android apps to call in to
CommCare at this position.{% endblocktrans %}"></span>
</label>
<div id="session-endpoint-id"
class="{% css_field_class %} commcare-feature"
data-since-version="2.51"
class="{% css_field_class %}">
<input class="code form-control"
type="text"
id="session_endpoint_id"
name="session_endpoint_id"
value="{{ form.session_endpoint_id|default:'' }}" />
</div>
</div>
<div class="form-group">
<label class="control-label {% css_label_class %}">
{% trans 'Allow endpoint to access hidden forms' %}
<span class="hq-help-template"
data-title="{% trans 'Allow access to hidden forms' %}"
data-content="{% blocktrans %}Turn this setting on to allow this endpoint to access
hidden forms.{% endblocktrans %}"></span>
</label>
<div id="access-hidden-forms"
class="{% css_field_class %} commcare-feature"
data-since-version="2.51"
class="{% css_field_class %}">
<input type="checkbox"
id="access_hidden_forms"
name="access_hidden_forms"
value="true"
style="margin-top: 10px"
{% comment %} respect_relevancy is an inverse condition of allowing access to hidden forms
{% endcomment %}
{% if form.respect_relevancy is False %} checked {% endif %}
/>
<input type="hidden" name="access_hidden_forms" value="false"/>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h4 class="panel-title panel-title-nolink">{% trans "Advanced" %}</h4>
{% 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 %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:'' }}" />
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ <h4 class="panel-title panel-title-nolink">{% trans "Advanced" %}</h4>
{% 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 %}
Expand Down
30 changes: 30 additions & 0 deletions corehq/apps/app_manager/tests/test_suite_session_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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'
suite = self.factory.app.create_suite()
self.assertXmlPartialEqual(
"""
<partial>
<endpoint id="my_form" respect-relevancy="false">
<argument id="case_id"/>
<stack>
<push>
<datum id="case_id" value="$case_id"/>
<command value="'claim_command.my_form.case_id'"/>
</push>
<push>
<command value="'m0'"/>
<datum id="case_id" value="$case_id"/>
<command value="'m0-f0'"/>
</push>
</stack>
</endpoint>
</partial>
""",
suite,
"./endpoint",
)


@patch_validate_xform()
@patch_get_xform_resource_overrides()
Expand Down
3 changes: 3 additions & 0 deletions corehq/apps/app_manager/views/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('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']:
form.function_datum_endpoints = request.POST['function_datum_endpoints'].replace(" ", "").split(",")
Expand Down

0 comments on commit e335dcf

Please sign in to comment.