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 scope_filter(self): # Filter to be applied in AND with filters for export to add scope for restricted user # Restricts to cases owned by accessible locations and their respective users Or Cases # Last Modified by accessible users accessible_location_ids = (SQLLocation.active_objects.accessible_location_ids( self.request.domain, self.request.couch_user) ) accessible_user_ids = user_ids_at_locations(accessible_location_ids) accessible_ids = accessible_user_ids + list(accessible_location_ids) return case_es.owner(accessible_ids)
def query_all_project_data(query, domain, mobile_user_and_group_slugs): # Show everything but stuff we know for sure to exclude user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) ids_to_exclude = _get_special_owner_ids( domain=domain, 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, ) return query.NOT(case_es.owner(ids_to_exclude))
def _build_query(self): query = (case_es.CaseES() .domain(self.domain) .size(self.pagination.count) .start(self.pagination.start)) query.es_query['sort'] = self.get_sorting_block() 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 EMWF.show_all_data(self.request): pass elif EMWF.show_project_data(self.request): # Show everything but stuff we know for sure to exclude user_types = EMWF.selected_user_types(self.request) ids_to_exclude = self.get_special_owner_ids( admin=HQUserType.ADMIN not in user_types, unknown=HQUserType.UNKNOWN not in user_types, demo=HQUserType.DEMO_USER not in user_types, commtrack=False, ) query = query.NOT(case_es.owner(ids_to_exclude)) else: # Only show explicit matches query = query.owner(self.case_owners) search_string = SearchFilter.get_value(self.request, self.domain) if search_string: query = query.set_query({"query_string": {"query": search_string}}) return query
def to_es_filter(self): return owner(self.owner_id)
def blacklist_owner_id(owner_id): return filters.NOT(owner(owner_id))
def deactivated_case_owners(domain): owner_ids = ( user_es.UserES().show_only_inactive().domain(domain).get_ids()) return case_es.owner(owner_ids)
def query_location_restricted_cases(query, request): accessible_ids = _get_location_accessible_ids(request) return query.filter(case_es.owner(accessible_ids))
def query_deactivated_data(query, domain): owner_ids = ( user_es.UserES().show_only_inactive().domain(domain).get_ids()) return query.filter(case_es.owner(owner_ids))
def query_deactivated_data(query, domain): owner_ids = (user_es.UserES() .show_only_inactive() .domain(domain) .get_ids()) return query.OR(case_es.owner(owner_ids))
def query_location_restricted_cases(query, request): accessible_ids = _get_location_accessible_ids(request) return query.OR(case_es.owner(accessible_ids))