-
-
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
improve report filtering related to system forms #31654
Changes from all commits
2363716
c19f787
54c51aa
6c145da
8fda9ee
a5be2b2
d8d4346
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,12 @@ def default_datespan(self): | |
return datespan_from_beginning(self.domain_object, self.timezone) | ||
|
||
def _get_users_filter(self, mobile_user_and_group_slugs): | ||
if ( | ||
EMWF.no_filters_selected(mobile_user_and_group_slugs) | ||
and self.request.couch_user.has_permission(self.domain, 'access_all_locations') | ||
): | ||
return None | ||
|
||
user_ids = (EMWF.user_es_query(self.domain, | ||
mobile_user_and_group_slugs, | ||
self.request.couch_user) | ||
|
@@ -102,20 +108,20 @@ def es_query(self): | |
query = (form_es.FormES() | ||
.domain(self.domain) | ||
.filter(time_filter(gte=self.datespan.startdate, | ||
lt=self.datespan.enddate_adjusted)) | ||
.filter(self._get_users_filter(mobile_user_and_group_slugs))) | ||
lt=self.datespan.enddate_adjusted))) | ||
|
||
users_filter = self._get_users_filter(mobile_user_and_group_slugs) | ||
if users_filter: | ||
query = query.filter(users_filter) | ||
|
||
# filter results by app and xmlns if applicable | ||
if FormsByApplicationFilter.has_selections(self.request): | ||
form_values = list(self.all_relevant_forms.values()) | ||
if form_values: | ||
query = query.OR(*[self._form_filter(f) for f in form_values]) | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aside: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree but if you to select it and not change anything else then it does change the results to only include 'known forms'. I toyed with changing but the added complexity didn't seem worth it in the context of this PR. |
||
query = query.NOT(es_filters.missing("app_id")) | ||
|
||
# Exclude system forms unless they selected "Unknown User" | ||
if HQUserType.UNKNOWN not in EMWF.selected_user_types(mobile_user_and_group_slugs): | ||
query = query.NOT(form_es.xmlns( | ||
list(SYSTEM_FORM_XMLNS_MAP.keys()) | ||
)) | ||
return query | ||
|
||
@property | ||
|
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.
That's neat - I didn't know this was part of the query language: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_missing_value_5