def _build_query(self): query = (self.search_class() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and (EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs)): pass elif self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs): # Show everything but stuff we know for sure to exclude ids_to_exclude = self.get_special_owner_ids( admin=HQUserType.ADMIN not in user_types, unknown=HQUserType.UNKNOWN not in user_types, web=HQUserType.WEB not in user_types, demo=HQUserType.DEMO_USER not in user_types, commtrack=False, ) query = query.NOT(case_es.owner(ids_to_exclude)) elif self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs): owner_ids = (user_es.UserES() .show_only_inactive() .domain(self.domain) .get_ids()) query = query.OR(case_es.owner(owner_ids)) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query.OR(self.scope_filter()) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _build_query(self): query = (self.search_class().domain(self.domain).size( self.pagination.count).start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and ( EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs)): pass elif self.request.can_access_all_locations and EMWF.show_project_data( mobile_user_and_group_slugs): # Show everything but stuff we know for sure to exclude ids_to_exclude = self.get_special_owner_ids( admin=HQUserType.ADMIN not in user_types, unknown=HQUserType.UNKNOWN not in user_types, web=HQUserType.WEB not in user_types, demo=HQUserType.DEMO_USER not in user_types, commtrack=False, ) query = query.NOT(case_es.owner(ids_to_exclude)) elif self.request.can_access_all_locations and EMWF.show_deactivated_data( mobile_user_and_group_slugs): owner_ids = (user_es.UserES().show_only_inactive().domain( self.domain).get_ids()) query = query.OR(case_es.owner(owner_ids)) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query.OR(self.scope_filter()) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _build_query(self): query = (self.search_class().domain(self.domain).size( self.pagination.count).start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') case_owner_filters = [] if (self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs)): case_owner_filters.append( all_project_data_filter(self.domain, mobile_user_and_group_slugs)) if (self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs)): case_owner_filters.append(deactivated_case_owners(self.domain)) # Only show explicit matches if (EMWF.selected_user_ids(mobile_user_and_group_slugs) or EMWF.selected_user_types(mobile_user_and_group_slugs) or EMWF.selected_group_ids(mobile_user_and_group_slugs) or EMWF.selected_location_ids(mobile_user_and_group_slugs)): track_es_report_load(self.domain, self.slug, len(self.case_owners)) case_owner_filters.append(case_es.owner(self.case_owners)) query = query.OR(*case_owner_filters) if not self.request.can_access_all_locations: query = query_location_restricted_cases(query, self.request) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def _build_query(self): query = (self.search_class() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) if self.case_filter: query = query.filter(self.case_filter) query = query.NOT(case_es.case_type("user-owner-mapping-case")) if self.case_type: query = query.case_type(self.case_type) if self.case_status: query = query.is_closed(self.case_status == 'closed') if self.request.can_access_all_locations and ( EMWF.show_all_data(mobile_user_and_group_slugs) or EMWF.no_filters_selected(mobile_user_and_group_slugs) ): pass elif (self.request.can_access_all_locations and EMWF.show_project_data(mobile_user_and_group_slugs)): query = query_all_project_data( query, self.domain, mobile_user_and_group_slugs ) elif (self.request.can_access_all_locations and EMWF.show_deactivated_data(mobile_user_and_group_slugs)): query = query_deactivated_data(query, self.domain) else: # Only show explicit matches query = query.owner(self.case_owners) if not self.request.can_access_all_locations: query = query_location_restricted_cases(query, self.request) search_string = CaseSearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query