def _get_filters_from_slugs(self, mobile_user_and_group_slugs, can_access_all_locations): """ for full organization access: for selected groups return group ids and groups user ids otherwise fetches case sharing groups and locations ids for restricted access: fetches case sharing location ids :return: set of filters using OwnerFilter and LastModifiedByFilter along with group independent filters """ group_ids = None if can_access_all_locations: group_ids = self._get_group_ids(mobile_user_and_group_slugs) owner_filter_ids = [] last_modified_filter_ids = [] if group_ids: groups_static_user_ids = Group.get_static_user_ids_for_groups(group_ids) groups_static_user_ids = flatten_non_iterable_list(groups_static_user_ids) owner_filter_ids = group_ids + groups_static_user_ids last_modified_filter_ids = groups_static_user_ids return [OR( OwnerFilter(owner_filter_ids), LastModifiedByFilter(last_modified_filter_ids), *self._get_group_independent_filters(mobile_user_and_group_slugs, can_access_all_locations) )]
def _scope_filter(self, accessible_location_ids): # 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_user_ids = user_ids_at_locations(list(accessible_location_ids)) accessible_ids = accessible_user_ids + list(accessible_location_ids) return OR(OwnerFilter(accessible_ids), LastModifiedByFilter(accessible_user_ids))
def _get_group_independent_filters(self, can_access_all_locations, selected_user_types, location_ids, user_ids): # filters for location and users for both and user type in case of full access if can_access_all_locations: user_types = selected_user_types ids_to_include = self.get_user_ids_for_user_types( admin=HQUserType.ADMIN in user_types, unknown=HQUserType.UNKNOWN in user_types, web=HQUserType.WEB in user_types, demo=HQUserType.DEMO_USER in user_types, commtrack=False, ) default_filters = [OwnerFilter(ids_to_include)] else: default_filters = [] # filters for cases owned by users at selected locations and their descendants default_filters.append(self._get_locations_filter(location_ids)) #default_filters.append(self.export_user_filter(location_ids)) # filters for cases owned by selected locations and their descendants default_filters.append( self.export_user_filter( self._get_selected_locations_and_descendants_ids( location_ids))) default_filters.append(self._get_users_filter(list(user_ids))) default_filters.append(LastModifiedByFilter(list(user_ids))) return [_f for _f in default_filters if _f]
def get_case_filter(self): group = self._get_group() if group: user_ids = set(group.get_static_user_ids()) case_filter = [OR( OwnerFilter(group._id), OwnerFilter(user_ids), LastModifiedByFilter(user_ids) )] else: case_sharing_groups = [g.get_id for g in Group.get_case_sharing_groups(self.domain_object.name)] case_filter = [OR( OwnerTypeFilter(self._get_es_user_types()), OwnerFilter(case_sharing_groups), LastModifiedByFilter(case_sharing_groups) )] date_filter = self._get_datespan_filter() if date_filter: case_filter.append(date_filter) return case_filter
def _get_group_independent_filters(self, mobile_user_and_group_slugs, can_access_all_locations): # filters for location and users for both and user type in case of full access if can_access_all_locations: user_types = self.dynamic_filter_class.selected_user_types(mobile_user_and_group_slugs) ids_to_include = self.get_user_ids_for_user_types( admin=HQUserType.ADMIN in user_types, unknown=HQUserType.UNKNOWN in user_types, demo=HQUserType.DEMO_USER in user_types, commtrack=False, ) default_filters = [OwnerFilter(ids_to_include)] else: default_filters = [] # filters for cases owned by users at selected locations and their descendants default_filters.append(self._get_locations_filter(mobile_user_and_group_slugs)) # filters for cases owned by selected locations and their descendants default_filters.append( self.export_user_filter(self._get_selected_locations_and_descendants_ids(mobile_user_and_group_slugs)) ) default_filters.append(self._get_users_filter(mobile_user_and_group_slugs)) default_filters.append(LastModifiedByFilter(self._get_user_ids(mobile_user_and_group_slugs))) return filter(None, default_filters)