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

ABDM changes for consuming APIs in the mobile app. #32194

Closed
wants to merge 188 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
17cbc8f
Removed safe from accept_invite
mjriley Jan 17, 2022
0ef7fa6
Removed the safe filter from userreports templates
mjriley Feb 9, 2022
45bc345
remove careplan report templates
mjriley Feb 11, 2022
d5dc397
remove safe from conditional alerts
mjriley Jan 17, 2022
5816f0b
Removed safe from SMS
mjriley Jan 17, 2022
3a3d1d9
Removed safe usage from users
mjriley Jan 17, 2022
0096518
Removed safe usages from HQAdmin
mjriley Jan 17, 2022
707b685
remove safe from domain templates
mjriley Jan 18, 2022
d2c22e6
Remove safe filter from report templates
mjriley Feb 9, 2022
281abd1
Removed safe filter from feature flags
mjriley Feb 9, 2022
f0480d4
Removed safe filter from fixtures
mjriley Feb 10, 2022
e4f4cce
Removed safe filter from accounting
mjriley Feb 10, 2022
75cee53
Remove safe filter from custom data fields
mjriley Feb 10, 2022
a2bc2f4
remove safe filter from openmrs
mjriley Feb 11, 2022
8332e93
Remove safe filter from inddex
mjriley Feb 11, 2022
00c2bc0
removed safe filter from casexml
mjriley Feb 14, 2022
7ac580b
Removed safe filter from app manager templates
mjriley Feb 15, 2022
3dce722
Removed safe filter from crispy text field
mjriley Feb 23, 2022
a3b9108
removed safe filter from crispy templates
mjriley Feb 24, 2022
2a676da
Removed unnecessary import
mjriley May 4, 2022
a41d145
fixed a variable naming issue
mjriley May 4, 2022
126cea1
Merge branch 'master' into mjr/safe_hqwebapp
mjriley May 4, 2022
56fc7fc
Removed additional safe filters from templates
mjriley May 4, 2022
580e4ba
Updated invite template style
mjriley May 5, 2022
67f9165
Merge branch 'mjr/safe_hqadmin' into mjr/mark_safe_combined
mjriley May 9, 2022
4709df6
Merge branch 'mjr/safe_app_manager' into mjr/mark_safe_combined
mjriley May 9, 2022
cb1869c
Merge branch 'mjr/safe_custom_data_fields' into mjr/mark_safe_combined
mjriley May 9, 2022
3be941b
Merge branch 'mjr/safe_motech' into mjr/mark_safe_combined
mjriley May 9, 2022
e33ba12
Merge branch 'mjr/safe_reports' into mjr/mark_safe_combined
mjriley May 9, 2022
804bebe
Merge branch 'mjr/safe_users' into mjr/mark_safe_combined
mjriley May 9, 2022
2121e22
Merge branch 'mjr/safe_sms' into mjr/mark_safe_combined
mjriley May 9, 2022
fb51e67
Merge branch 'mjr/safe_casexml' into mjr/mark_safe_combined
mjriley May 9, 2022
d8bc231
Merge branch 'mjr/safe_accounting' into mjr/mark_safe_combined
mjriley May 9, 2022
b77ba0e
Merge branch 'mjr/safe_fixtures' into mjr/mark_safe_combined
mjriley May 9, 2022
2b43e71
Merge branch 'mjr/safe_toggleui' into mjr/mark_safe_combined
mjriley May 9, 2022
777e777
Merge branch 'mjr/safe_domain' into mjr/mark_safe_combined
mjriley May 9, 2022
ebd9fd5
Merge branch 'mjr/safe_messaging' into mjr/mark_safe_combined
mjriley May 9, 2022
587a622
Merge branch 'mjr/safe_hqwebapp' into mjr/mark_safe_combined
mjriley May 9, 2022
5ea0f1a
Merge branch 'mjr/safe_userreports' into mjr/mark_safe_combined
mjriley May 9, 2022
00e0ccd
Merge branch 'mjr/report_careplan' into mjr/mark_safe_combined
mjriley May 9, 2022
59a0658
Merge branch 'mjr/safe_accept_invite' into mjr/mark_safe_combined
mjriley May 9, 2022
8668562
Updated DataTables output to be HTML-safe
mjriley May 10, 2022
be165a7
Merge branch 'mjr/safe_inddex' into mjr/all_safe_fixes
mjriley May 11, 2022
299f292
Break out username for easier traceback handling in signup
mjriley May 12, 2022
5954509
Fixed an issue for new users attempting to accept an invite
mjriley May 12, 2022
f3f3c29
Fixed conditional alert HTML artifact
mjriley May 16, 2022
6be3231
Fixed an HTML artifact bug with custom reports
mjriley May 25, 2022
0c6ce4b
Merge branch 'master' into mjr/all_safe_fixes
millerdev Jun 20, 2022
6e0e44c
Merge branch 'master' into mjr/all_safe_fixes
orangejenny Jul 1, 2022
fd5307e
CommCare HQ
kaapstorm Sep 14, 2022
2b3b509
Postgresql 14
millerdev Sep 7, 2022
3b6327d
Log service version info in test output
millerdev Sep 20, 2022
ba82c67
ABDM api for mobile app consumption
Sep 22, 2022
23d321b
Add abdm api token to response of mobile restore
Sep 22, 2022
424af6d
Add auth settings + register in primary urls.py
Sep 22, 2022
f7e8afd
abdm migrations
Sep 22, 2022
09c8c5a
add abdm exclusion to domain migration tests
Sep 22, 2022
496bd0b
Merge remote-tracking branch 'origin/master' into akj/abdm-api-for-mo…
Sep 26, 2022
d8e49bf
Refactor based on review comments
Sep 26, 2022
b96be7f
remove CRUDPaginatedViewMixin from AutomaticUpdateRuleListView
gherceg Sep 27, 2022
f759674
fix stickler JS warnings
gherceg Sep 27, 2022
5a48dce
first batch of addressing feedback
gherceg Sep 27, 2022
d9cce87
second batch of addressing feedback
gherceg Sep 27, 2022
13240dc
ignore stickler syntax error
gherceg Sep 27, 2022
53c2a7b
unwrap id in delete rule modal
gherceg Sep 28, 2022
f7917ab
move header and help text outside of tabs
gherceg Sep 28, 2022
56b14a5
use page_context, not main_context
gherceg Sep 28, 2022
847ec50
rename list_automatic_update_rules.js to deduplication_rules.js
gherceg Sep 29, 2022
24a16d5
duplicate format_rule code into deduplication list view (the irony)
gherceg Sep 30, 2022
5a620bd
Change the way a "for export" adapter is acquired
joxl Sep 26, 2022
5423bc1
Change document adapter usage pattern
joxl Sep 27, 2022
04f7876
Move `index_name` and `type` class attributes to init args
joxl Sep 27, 2022
276fd41
Update the manager adapter pattern to match document adapters
joxl Sep 27, 2022
e1aeba7
Overhaul `ElasticDocumentAdapter.update()`
joxl Sep 28, 2022
c8e5f47
Refactor `ElasticDocumentAdapter` keyword arguments
joxl Sep 30, 2022
6a5a30a
use get_timezone_for_user directly
gherceg Oct 17, 2022
1e37222
missing time from page context
gherceg Oct 17, 2022
fbc3d87
Merge branch 'master' into gh/replace-base-crud-view
gherceg Oct 18, 2022
01bdea4
basic implementation of rule run history tab
gherceg Sep 29, 2022
19c30b9
add paginated for rule run history tab
gherceg Oct 17, 2022
b434fc6
add num of updates and closes to table
gherceg Oct 17, 2022
be99017
filter DomainCaseRuleRun by case update workflow
gherceg Oct 18, 2022
d3c670b
add status field to table
gherceg Oct 18, 2022
0f142f0
refactor to ensure 'update rule' is not used
gherceg Oct 18, 2022
1d35b7d
misc: remove older django version compatibility
AmitPhulera Oct 19, 2022
2f304e2
misc: more docstring in transient_util
AmitPhulera Oct 19, 2022
9c0e723
add: Tombstone class
AmitPhulera Oct 19, 2022
b0bdda5
tests: Tomobstone class
AmitPhulera Oct 19, 2022
95bb118
refactor:set default property to None
AmitPhulera Oct 19, 2022
a6a26a4
refactor: some refactors to support the multiplexer class coming up
AmitPhulera Oct 19, 2022
6c86188
add: ElasticMultiplexAdapter class
AmitPhulera Oct 19, 2022
e8a9846
refactor: create_document_adapter to return multiplexer class if seco…
AmitPhulera Oct 19, 2022
bb0fd46
refactor: split helper functions into a sepearate test helper class
AmitPhulera Oct 19, 2022
4b86cad
add: tests for the multiplexer adapter
AmitPhulera Oct 19, 2022
e51a2da
add allowed_actions to dedupe view
gherceg Oct 19, 2022
0bec349
Merge branch 'gh/replace-base-crud-view' into gh/add-history-tab
gherceg Oct 20, 2022
0eed91a
add docstrings for tombstones
AmitPhulera Oct 20, 2022
643b2bb
update readme as per the changes in the PR
AmitPhulera Oct 20, 2022
da0ba4e
rename reference to auto_update_rule_run_history.html
gherceg Oct 20, 2022
7119925
move index cleanup from teardown to self.addCleanup
AmitPhulera Oct 20, 2022
44755b4
Update corehq/apps/es/transient_util.py
AmitPhulera Oct 20, 2022
eba1c36
pass fn instead of result in addCleanup
AmitPhulera Oct 21, 2022
a4c9792
sort rule runs by descending started and finished dates
gherceg Oct 23, 2022
bd20ea8
Add checkbox case search option to app manager
nospame Oct 24, 2022
e4d47ce
document usage for tombstones in readme
AmitPhulera Oct 25, 2022
5328d10
Add checkbox to case search query view
nospame Oct 25, 2022
d6b199f
Add checkbox prompt to xml tests
nospame Oct 25, 2022
1d099f8
Merge branch 'master' of github.com:dimagi/commcare-hq into em/case-s…
nospame Oct 25, 2022
0bc1aad
add mgmnt command to get es version when index was created
AmitPhulera Oct 26, 2022
8628a7e
remove confusing para from readme
AmitPhulera Oct 26, 2022
94436e6
Refactor
nospame Oct 26, 2022
3761567
bump default items per page from 5 to 25
gherceg Oct 27, 2022
ee5a952
Nitpicking
minhaminha Oct 28, 2022
e604d66
Shadow module to get persistent and inline details from itself instea…
SmittieC Oct 28, 2022
4496d8c
Refactor a bit
SmittieC Oct 28, 2022
2055e5f
remove unused methods
AddisonDunn Oct 31, 2022
6b16f49
add TableauUser, TableauGroup models
AddisonDunn Oct 31, 2022
60d5df1
Merge remote-tracking branch 'origin/master' into akj/abdm-api-for-mo…
Nov 1, 2022
69b5818
add translations for tableau roles
AddisonDunn Nov 1, 2022
961def7
Revert "Refactor"
nospame Nov 1, 2022
75fbce7
refactor - look for self.app on the EntriesHelper instead of passing …
SmittieC Nov 2, 2022
f4e73e8
changed default pagination to 25 on wrong table
gherceg Nov 2, 2022
54bf4c0
Use lookup tables in checkbox case search property
nospame Nov 2, 2022
df54e23
Allow multiple checkboxes in case search UI
nospame Nov 2, 2022
63bd5db
Stickler
nospame Nov 2, 2022
716051d
initial command to backfill subevent date
snopoke Nov 3, 2022
93b588c
update from sms
snopoke Nov 3, 2022
29bb536
backfill from xformsession
snopoke Nov 3, 2022
04260fd
make chunksize configurable
snopoke Nov 3, 2022
dbd9660
add migration status to command
snopoke Nov 3, 2022
6172be0
test that rows with dates are not updated
snopoke Nov 3, 2022
05a506d
combine tests into a single class
snopoke Nov 3, 2022
8486963
increase max length for username field
AddisonDunn Nov 3, 2022
492daad
Merge remote-tracking branch 'origin/master' into akj/abdm-api-for-mo…
Nov 6, 2022
2ed59f4
Merge pull request #32151 from dimagi/nh/commcare_hq_rst
kaapstorm Nov 7, 2022
850019b
Merge pull request #32289 from dimagi/ap/es-index-version-created
AmitPhulera Nov 7, 2022
0821b24
add more options for testing
snopoke Nov 7, 2022
7e85b13
fix backfill tests
snopoke Nov 7, 2022
8d58e89
Revert "[SAAS-14102] addf field to messaging sub-event model to recor…
snopoke Nov 7, 2022
3547632
Merge pull request #32314 from dimagi/revert-32307-sk/subevent-date-l…
snopoke Nov 7, 2022
aed8e7e
Revert "Revert "[SAAS-14102] addf field to messaging sub-event model …
snopoke Nov 7, 2022
ebed0b8
set 'auto_now' in a separate migration to avoid table lock on the ini…
snopoke Nov 7, 2022
1943140
improve query performance
snopoke Nov 7, 2022
987ee41
add count query for better progress & refactor
snopoke Nov 7, 2022
4db0721
Merge pull request #32302 from dimagi/ad/create-other-tableau-syncing…
AddisonDunn Nov 7, 2022
b9047da
skip if no rows
snopoke Nov 7, 2022
a4eb5c9
lower defualt chunksize
snopoke Nov 7, 2022
6424929
Merge pull request #32315 from dimagi/revert-32314-revert-32307-sk/su…
snopoke Nov 7, 2022
b379963
Merge branch 'master' into sk/backfill-subevent-date
snopoke Nov 7, 2022
d4eb4b2
Optimize EnterpriseFormReport.total_for_domain()
millerdev Nov 7, 2022
7235e7f
Feature flag for restore content
Nov 8, 2022
6587471
Use extensions for fetching abdm token in restore
Nov 8, 2022
d9a2787
Merge pull request #32298 from dimagi/cs/sc-2369/shadow_module_fix
SmittieC Nov 8, 2022
a9671d9
Merge pull request #32311 from dimagi/sk/backfill-subevent-date
snopoke Nov 8, 2022
7883b48
update API to use new date field for sorting
snopoke Nov 8, 2022
07b6743
Merge pull request #32317 from dimagi/dm/optimize-enterprise-forms-re…
millerdev Nov 8, 2022
11d5047
Merge branch 'master' into dm/pg14
millerdev Nov 8, 2022
502d1e1
DRY postgres version and warn on outdated pin
millerdev Nov 8, 2022
0071f2f
Merge pull request #32120 from dimagi/dm/pg14
millerdev Nov 8, 2022
e78d971
Update staging.yml
minhaminha Nov 8, 2022
cdc21fd
Updated EOF nav config to use select2
orangejenny Nov 8, 2022
b157ed6
Merge pull request #32288 from dimagi/mjr/all_safe_fixes
minhaminha Nov 8, 2022
cab23cc
Fix html typo
nospame Nov 8, 2022
a238477
Show multiselect disabled + checked for checkbox property
nospame Nov 8, 2022
bdea408
updating files: scripts/staging.yml
nospame Nov 8, 2022
b66f25d
Merge pull request #32211 from dimagi/gh/replace-base-crud-view
gherceg Nov 8, 2022
d291ae3
Update staging.yml
gherceg Nov 8, 2022
32d2961
Update translations
dannyroberts Nov 9, 2022
3e5e07e
Merge pull request #32265 from dimagi/jm+ap/elastic-multiplexer
AmitPhulera Nov 9, 2022
9a7d94b
Merge pull request #32323 from dimagi/jls/eof-nav-select2s
orangejenny Nov 9, 2022
17c0050
only check for data registry if not remote link
gherceg Nov 9, 2022
88c05d5
add search box to rule run table
gherceg Nov 9, 2022
4830ebe
add brief description of rule run history table
gherceg Nov 9, 2022
f1ae3ec
Merge pull request #32290 from dimagi/em/case-search-checkbox
nospame Nov 9, 2022
6083729
use datasource var in data registry check
gherceg Nov 9, 2022
d234d42
datasource as optional param in is_data_registry_report
gherceg Nov 9, 2022
3f6b2fb
Update staging.yml
gherceg Nov 9, 2022
5edb2ac
update description for rule run history table
gherceg Nov 9, 2022
48e79ca
Merge pull request #32324 from dimagi/create-pull-request/update-tran…
joxl Nov 9, 2022
3d8615b
updating files: scripts/staging.yml
esoergel Nov 9, 2022
31a846a
Merge pull request #32326 from dimagi/gh/resolve-remote-link-issue
gherceg Nov 9, 2022
f518467
Update staging.yml
gherceg Nov 9, 2022
6b5d317
Merge pull request #32258 from dimagi/gh/add-history-tab
gherceg Nov 9, 2022
44b9aa2
Update staging.yml
gherceg Nov 9, 2022
1274cfd
update staging
snopoke Nov 10, 2022
8e7f4a2
Merge pull request #32322 from dimagi/sk/messaging-api-new-date-field
snopoke Nov 10, 2022
52bd4d1
Merge branch 'akj/abdm-api-for-mobile-app' of https://github.com/dima…
Nov 11, 2022
1094b43
remove drf default auth from settings.py
Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
==========================
Contributing to CommCareHQ
==========================
===========================
Contributing to CommCare HQ
===========================

CommCareHQ is primarily developed by `Dimagi`_, but we welcome contributions.
CommCare HQ is primarily developed by `Dimagi`_, but we welcome contributions.

Code Contributions
------------------
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django Apps in CommCareHQ
#########################
Django Apps in CommCare HQ
##########################

Most CommCare HQ functionality is contained in a django app.
A few areas are contained in ``corehq`` or ``corehq/ex-submodules``,
Expand Down
27 changes: 10 additions & 17 deletions corehq/apps/accounting/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,23 +579,18 @@ def __init__(self, subscription, account_id, web_user, *args, **kwargs):
self.fields['account'].initial = subscription.account.id
account_field = hqcrispy.B3TextField(
'account',
'<a href="%(account_url)s">%(account_name)s</a>' % {
'account_url': reverse(ManageBillingAccountView.urlname,
args=[subscription.account.id]),
'account_name': subscription.account.name,
}
format_html('<a href="{}">{}</a>',
reverse(ManageBillingAccountView.urlname, args=[subscription.account.id]),
subscription.account.name)
)

self.fields['plan_version'].initial = subscription.plan_version.id
plan_version_field = hqcrispy.B3TextField(
'plan_version',
'<a href="%(plan_version_url)s">%(plan_name)s</a>' % {
'plan_version_url': reverse(
SoftwarePlanVersionView.urlname,
args=[subscription.plan_version.plan.id, subscription.plan_version_id]
),
'plan_name': subscription.plan_version,
},
format_html('<a href="{}">{}</a>',
reverse(SoftwarePlanVersionView.urlname,
args=[subscription.plan_version.plan.id, subscription.plan_version_id]),
subscription.plan_version)
)
self.fields['plan_edition'].initial = subscription.plan_version.plan.edition
plan_edition_field = hqcrispy.B3TextField(
Expand All @@ -610,11 +605,9 @@ def __init__(self, subscription, account_id, web_user, *args, **kwargs):

domain_field = hqcrispy.B3TextField(
'domain',
'<a href="%(project_url)s">%(project_name)s</a>' % {
'project_url': reverse(DefaultProjectSettingsView.urlname,
args=[subscription.subscriber.domain]),
'project_name': subscription.subscriber.domain,
},
format_html('<a href="{}">{}</a>',
reverse(DefaultProjectSettingsView.urlname, args=[subscription.subscriber.domain]),
subscription.subscriber.domain)
)

self.fields['start_date'].initial = subscription.date_start.isoformat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h4 class="text-center">
{{ message.message }}
<ul>
{% for detail in message.details %}
<li>{{ detail|safe }}</li>
<li>{{ detail }}</li>
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div style="overflow: auto">
<table class="table table-striped datatable">
<thead>
{{ headers.render_html|safe }}
{{ headers.render_html }}
</thead>
<tbody>
{% block tabular-body %}
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/api/resources/messaging_event/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _consumer(key, value):

COMPOUND_FILTERS = [
_get_date_filter_consumer("date"),
_get_date_filter_consumer("date_last_activity", "date_last_activity_computed"),
_get_date_filter_consumer("date_last_activity"),
]

SIMPLE_FILTERS = {
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/api/resources/messaging_event/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def serialize_event(event):
"id": event.id,
"content_type": MessagingEvent.CONTENT_TYPE_SLUGS.get(event.content_type, "unknown"),
"date": event.date.isoformat(),
"date_last_activity": event.date_last_activity_computed.isoformat(),
"date_last_activity": event.date_last_activity.isoformat(),
"case_id": event.case_id,
"domain": event.parent.domain,
"error": _serialize_event_error(event),
Expand Down
6 changes: 1 addition & 5 deletions corehq/apps/api/resources/messaging_event/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def get_order_by_field(request_params):
if order_by not in ("date", "-date", "date_last_activity", "-date_last_activity"):
raise BadRequest(_("No matching '{field_name}' field for ordering").format(field_name=order_by))

# rename to query field
return {
"date_last_activity": "date_last_activity_computed",
"-date_last_activity": "-date_last_activity_computed"
}.get(order_by, order_by)
return order_by


@attrs
Expand Down
25 changes: 1 addition & 24 deletions corehq/apps/api/resources/messaging_event/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,4 @@ def _get_list(request):


def _get_base_query(domain):
"""The base query includes a 'date_last_activity_computed' field. This field
is calculated as:
Max(
event.date,
xform_session.modified_time, # if it exists
Max(sms.date_modified), # max for the current event
Max(email.date_modified) # max for the current event
)
"""
query = MessagingSubEvent.objects.select_related("parent").filter(parent__domain=domain)
newest_sms = (
SMS.objects.filter(messaging_subevent=OuterRef('pk'))
.order_by('-date_modified')
.values('date_modified')[:1]
)
newest_email = (
Email.objects.filter(messaging_subevent=OuterRef('pk'))
.order_by('-date_modified')
.values('date_modified')[:1]
)
query = query.annotate(date_last_activity_computed=Greatest(
'date', 'xforms_session__modified_time', Subquery(newest_sms), Subquery(newest_email)
))
return query
return MessagingSubEvent.objects.select_related("parent").filter(parent__domain=domain)
30 changes: 11 additions & 19 deletions corehq/apps/api/tests/test_es.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
from django.test import SimpleTestCase

from corehq.apps.es.tests.utils import es_test
from corehq.apps.es.client import ElasticManageAdapter
from corehq.apps.es.cases import ElasticCase
from corehq.apps.es.client import manager
from corehq.apps.es.cases import ElasticCase, case_adapter
from corehq.util.es.elasticsearch import TransportError

from ..es import CaseESView


class ElasticCase2(ElasticCase):

type = "type2"
mapping = ElasticCase().mapping # TODO: remove with transient_util
mapping = case_adapter.mapping


@es_test
class TestESView(SimpleTestCase):

def setUp(self):
super().setUp()
self.manager = ElasticManageAdapter()
self.cases = ElasticCase()
self._purge_indices()
self.manager.index_create(self.cases.index_name)
self.manager.index_put_mapping(self.cases.index_name, self.cases.type,
self.cases.mapping)
self.manager.index_put_alias(self.cases.index_name, CaseESView.es_alias)

def tearDown(self):
self._purge_indices()
super().tearDown()
self.cases = case_adapter
manager.index_create(self.cases.index_name)
self.addCleanup(self._purge_indices)
manager.index_put_mapping(self.cases.index_name, self.cases.type, self.cases.mapping)
manager.index_put_alias(self.cases.index_name, CaseESView.es_alias)

def _purge_indices(self):
try:
self.manager.index_delete(self.cases.index_name)
manager.index_delete(self.cases.index_name)
except TransportError:
# TransportError(404, 'index_not_found_exception', 'no such index')
pass
Expand Down Expand Up @@ -63,8 +55,8 @@ def mk_doc(doc_id, location_id):
self.assertEqual(doc_ny, to_dict(view.get_document(doc_id)))

# index a doc with a new _type ('type2')
cases_type2 = ElasticCase2()
self.manager.index_put_mapping(cases_type2.index_name, cases_type2.type,
cases_type2 = ElasticCase2(case_adapter.index_name, "type2")
manager.index_put_mapping(cases_type2.index_name, cases_type2.type,
cases_type2.mapping)
doc_dc = mk_doc(doc_id, "DC")
cases_type2.index(doc_dc, refresh=True)
Expand Down
45 changes: 22 additions & 23 deletions corehq/apps/api/tests/test_messaging_event_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import urllib.parse
from datetime import datetime, timedelta
from operator import attrgetter
from urllib.parse import urlencode

from django.urls import reverse
Expand Down Expand Up @@ -81,15 +82,15 @@ def test_date_ordering(self):

def test_date_last_activity_ordering(self):
sms = _create_sms_messages(self.domain, 5, randomize=True)
sms[0].save() # this should move this one to the end of the list
sms[0].messaging_subevent.save() # this should move this one to the end of the list

response = self._auth_get_resource(f'{self.list_endpoint}?order_by=date_last_activity')
self.assertEqual(response.status_code, 200, response.content)
ordered_data = json.loads(response.content)['objects']
self.assertEqual(5, len(ordered_data))
dates = [r['date_last_activity'] for r in ordered_data]
expected_order = sms[1:] + [sms[0]] # modification order
self.assertEqual(dates, [s.date_modified.isoformat() for s in expected_order])
self.assertEqual(dates, [s.messaging_subevent.date_last_activity.isoformat() for s in expected_order])

response = self._auth_get_resource(f'{self.list_endpoint}?order_by=-date_last_activity')
self.assertEqual(response.status_code, 200, response.content)
Expand Down Expand Up @@ -211,7 +212,7 @@ def test_case_rule(self):
"case_id": None,
"content_type": "sms",
"date": "2016-01-01T12:00:00",
"date_last_activity": sms.date_modified.isoformat(),
"date_last_activity": event.date_last_activity.isoformat(),
"domain": "qwerty",
"error": None,
"form": None,
Expand Down Expand Up @@ -258,11 +259,13 @@ def test_survey_sms(self):
self.addCleanup(event.delete) # cascades to subevent
self.addCleanup(sms.delete)

subevent = event.subevents[0]

expected = {
"case_id": None,
"content_type": "ivr-survey",
"date": "2016-01-01T12:00:00",
"date_last_activity": sms.date_modified.isoformat(),
"date_last_activity": subevent.date_last_activity.isoformat(),
"domain": "qwerty",
"error": None,
"form": {
Expand Down Expand Up @@ -315,7 +318,7 @@ def test_email(self):
"case_id": None,
"content_type": "email",
"date": event.date.isoformat(),
"date_last_activity": email.date_modified.isoformat(),
"date_last_activity": event.date_last_activity.isoformat(),
"domain": "qwerty",
"error": None,
"form": None,
Expand Down Expand Up @@ -367,7 +370,7 @@ def test_email_null_date_modified(self):
data = json.loads(response.content)['objects']
self.assertEqual(1, len(data))
for result in data:
self.assertEqual(result["date_last_activity"], event.date.isoformat())
self.assertEqual(result["date_last_activity"], event.date_last_activity.isoformat())
self.assertIsNone(result["messages"][0]["date_modified"])

def test_cursor(self):
Expand Down Expand Up @@ -532,21 +535,18 @@ def test_email_date_last_activity_filtering(self):
user = CommCareUser.create(self.domain.name, f"bob{i}", "123", None, None, email=f"bob{i}@email.com")
self.addCleanup(user.delete, self.domain.name, deleted_by=None)
user_ids.append(user.get_id)
events = make_email_event_for_test(self.domain.name, "test broadcast", user_ids)

emails = [
Email.objects.get(messaging_subevent=events[user_id]) for user_id in user_ids
]
emails[0].save() # update date_modified
expected_order = emails[1:] + [emails[0]] # modification order
dates = [email.date_modified for email in expected_order]
events_by_user = make_email_event_for_test(self.domain.name, "test broadcast", user_ids)
events = list(sorted(events_by_user.values(), key=attrgetter('date_last_activity')))
events[0].save() # update date_last_activity
expected_order = events[1:] + [events[0]] # modification order
dates = [event.date_last_activity for event in expected_order]

self._check_date_filtering_response({
f"{self.field}.lt": dates[3].isoformat()
}, [d.isoformat() for d in dates[:3]])

def test_survey_date_last_activity_filter(self):
sessions = []
events = []
messages = []
for i in range(5):
rule, xforms_session, event, sms = make_survey_sms_for_test(
Expand All @@ -556,26 +556,25 @@ def test_survey_date_last_activity_filter(self):
self.addCleanup(xforms_session.delete)
self.addCleanup(event.delete) # cascades to subevent
self.addCleanup(sms.delete)
sessions.append(xforms_session)
events.append(event.subevents[0])
messages.append(sms)

# update modified time for 1st session to move it to the end of the list
sessions[0].modified_time = datetime.utcnow()
sessions[0].save()
events[0].save()

# last_activity_date will be the max date so use sms dates except for the session that was updated
dates = [sms.date_modified for sms in messages[1:]] + [sessions[0].modified_time] # modification order
expected_order = events[1:] + [events[0]] # modification order
dates = [event.date_last_activity for event in expected_order]

self._check_date_filtering_response({
f"{self.field}.lt": dates[3].isoformat()
}, [d.isoformat() for d in dates[:3]])

def _setup_for_date_filter_test(self):
results = _create_sms_messages(self.domain, 5, randomize=True)
results[0].save() # update modification date
results[0].messaging_subevent.save() # update modification date
expected_order = results[1:] + [results[0]] # modification order
return list(
sms.date_modified for sms in expected_order
sms.messaging_subevent.date_last_activity for sms in expected_order
)


Expand All @@ -592,7 +591,7 @@ def _serialized_messaging_event(sms):
"id": sms.messaging_subevent_id,
"content_type": "sms",
"date": "2016-01-01T12:00:00",
"date_last_activity": sms.date_modified.isoformat() if sms.date_modified else "2016-01-01T12:00:00",
"date_last_activity": sms.messaging_subevent.date_last_activity.isoformat(),
"case_id": None,
"domain": "qwerty",
"error": None,
Expand Down
4 changes: 3 additions & 1 deletion corehq/apps/app_manager/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django import forms
from django.http import Http404
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _

from memoized import memoized
Expand Down Expand Up @@ -98,7 +99,8 @@ def __init__(self, enable_raw=False, enable_registry=False, registry_permission_
widget=forms.Select(choices=source_choices))

self.source_field = forms.ChoiceField(label=_('Data Source'), widget=forms.Select())
self.source_field.label = '<span data-bind="text: labelMap[sourceType()]"></span>'
self.source_field.label = mark_safe( # nosec: no user input
'<span data-bind=\'text: labelMap[sourceType()]\'></span>')

self.registry_slug_field = forms.ChoiceField(label=_('Data Registry'), widget=forms.HiddenInput,
required=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ hqDefine("app_manager/js/details/case_claim", function () {
var itemLists = get('js_options').item_lists;
return _.map(
_.filter(itemLists, function (p) {
return p.fixture_type === self.appearance();
return (
p.fixture_type === self.appearance()
|| (p.fixture_type === 'lookup_table_fixture' && self.appearance() === 'checkbox')
);
}),
function (p) {
return {
Expand Down Expand Up @@ -300,15 +303,14 @@ hqDefine("app_manager/js/details/case_claim", function () {
var uri = searchProperty.itemset.instance_uri;
if (uri !== null && uri.includes("commcare-reports")) {
appearance = "report_fixture";
}
else {
} else {
appearance = "lookup_table_fixture";
}
}
if (searchProperty.appearance === "address") {
appearance = "address";
}
if (["date", "daterange"].indexOf(searchProperty.input_) !== -1) {
if (["date", "daterange", "checkbox"].indexOf(searchProperty.input_) !== -1) {
appearance = searchProperty.input_;
}
return appearance;
Expand Down
Loading