def case_owners(self): # Get user ids for each user that match the demo_user, admin, # Unknown Users, or All Mobile Workers filters mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) special_owner_ids = self.get_special_owner_ids( admin=HQUserType.ADMIN in user_types, unknown=HQUserType.UNKNOWN in user_types, demo=HQUserType.DEMO_USER in user_types, commtrack=HQUserType.COMMTRACK in user_types, ) # Get user ids for each user that was specifically selected selected_user_ids = EMWF.selected_user_ids(mobile_user_and_group_slugs) # Get group ids for each group that was specified selected_reporting_group_ids = EMWF.selected_reporting_group_ids( mobile_user_and_group_slugs) selected_sharing_group_ids = EMWF.selected_sharing_group_ids( mobile_user_and_group_slugs) # Show cases owned by any selected locations, user locations, or their children loc_ids = set( EMWF.selected_location_ids(mobile_user_and_group_slugs) + get_users_location_ids(self.domain, selected_user_ids)) location_owner_ids = get_locations_and_children(loc_ids).location_ids() # Get user ids for each user in specified reporting groups report_group_q = HQESQuery(index="groups").domain(self.domain)\ .doc_type("Group")\ .filter(filters.term("_id", selected_reporting_group_ids))\ .fields(["users"]) user_lists = [group["users"] for group in report_group_q.run().hits] selected_reporting_group_users = list(set().union(*user_lists)) # Get ids for each sharing group that contains a user from selected_reporting_group_users OR a user that was specifically selected share_group_q = (HQESQuery(index="groups").domain( self.domain).doc_type("Group").term("case_sharing", True).term( "users", (selected_reporting_group_users + selected_user_ids)).fields( [])) sharing_group_ids = share_group_q.run().doc_ids owner_ids = list(set().union( special_owner_ids, selected_user_ids, selected_sharing_group_ids, selected_reporting_group_users, sharing_group_ids, location_owner_ids, )) return owner_ids
def case_owners(self): # Get user ids for each user that match the demo_user, admin, # Unknown Users, or All Mobile Workers filters mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) special_owner_ids = self.get_special_owner_ids( admin=HQUserType.ADMIN in user_types, unknown=HQUserType.UNKNOWN in user_types, demo=HQUserType.DEMO_USER in user_types, commtrack=HQUserType.COMMTRACK in user_types, ) # Get user ids for each user that was specifically selected selected_user_ids = EMWF.selected_user_ids(mobile_user_and_group_slugs) # Get group ids for each group that was specified selected_reporting_group_ids = EMWF.selected_reporting_group_ids(mobile_user_and_group_slugs) selected_sharing_group_ids = EMWF.selected_sharing_group_ids(mobile_user_and_group_slugs) # Show cases owned by any selected locations, user locations, or their children loc_ids = set(EMWF.selected_location_ids(mobile_user_and_group_slugs) + get_users_location_ids(self.domain, selected_user_ids)) location_owner_ids = get_locations_and_children(loc_ids).location_ids() # Get user ids for each user in specified reporting groups report_group_q = HQESQuery(index="groups").domain(self.domain)\ .doc_type("Group")\ .filter(filters.term("_id", selected_reporting_group_ids))\ .fields(["users"]) user_lists = [group["users"] for group in report_group_q.run().hits] selected_reporting_group_users = list(set().union(*user_lists)) # Get ids for each sharing group that contains a user from selected_reporting_group_users OR a user that was specifically selected share_group_q = (HQESQuery(index="groups") .domain(self.domain) .doc_type("Group") .term("case_sharing", True) .term("users", (selected_reporting_group_users + selected_user_ids)) .fields([])) sharing_group_ids = share_group_q.run().doc_ids owner_ids = list(set().union( special_owner_ids, selected_user_ids, selected_sharing_group_ids, selected_reporting_group_users, sharing_group_ids, location_owner_ids, )) return owner_ids
def get_case_owners(request, domain, mobile_user_and_group_slugs): """ For unrestricted user :return: user ids for selected user types for selected reporting group ids, returns user_ids belonging to these groups also finds the sharing groups which has any user from the above reporting group selected sharing group ids selected user ids also finds the sharing groups which has any user from the above selected users ids and descendants ids of assigned locations to these users ids and descendants ids of selected locations assigned users at selected locations and their descendants For restricted user :return: selected user ids also finds the sharing groups which has any user from the above selected users ids and descendants ids of assigned locations to these users ids and descendants ids of selected locations assigned users at selected locations and their descendants """ special_owner_ids, selected_sharing_group_ids, selected_reporting_group_users = [], [], [] sharing_group_ids, location_owner_ids, assigned_user_ids_at_selected_locations = [], [], [] if request.can_access_all_locations: user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) special_owner_ids = _get_special_owner_ids( domain=domain, 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=HQUserType.COMMTRACK in user_types, ) # Get group ids for each group that was specified selected_reporting_group_ids = EMWF.selected_reporting_group_ids( mobile_user_and_group_slugs) selected_sharing_group_ids = EMWF.selected_sharing_group_ids( mobile_user_and_group_slugs) # Get user ids for each user in specified reporting groups selected_reporting_group_users = [] if selected_reporting_group_ids: report_group_q = (HQESQuery( index="groups").domain(domain).doc_type("Group").filter( filters.term("_id", selected_reporting_group_ids)).fields( ["users"])) user_lists = [ group["users"] for group in report_group_q.run().hits ] selected_reporting_group_users = list(set().union(*user_lists)) # Get user ids for each user that was specifically selected selected_user_ids = EMWF.selected_user_ids(mobile_user_and_group_slugs) # Show cases owned by any selected locations, user locations, or their children loc_ids = set(EMWF.selected_location_ids(mobile_user_and_group_slugs)) if loc_ids: # Get users at selected locations and descendants assigned_user_ids_at_selected_locations = user_ids_at_locations_and_descendants( loc_ids) # Get user ids for each user in specified reporting groups if selected_user_ids: loc_ids.update(get_users_location_ids(domain, selected_user_ids)) location_owner_ids = [] if loc_ids: location_owner_ids = SQLLocation.objects.get_locations_and_children_ids( loc_ids) sharing_group_ids = [] if selected_reporting_group_users or selected_user_ids: # Get ids for each sharing group that contains a user from # selected_reporting_group_users OR a user that was specifically selected sharing_group_ids = (HQESQuery( index="groups").domain(domain).doc_type("Group").term( "case_sharing", True).term("users", (selected_reporting_group_users + selected_user_ids)).get_ids()) owner_ids = list(set().union( special_owner_ids, selected_user_ids, selected_sharing_group_ids, selected_reporting_group_users, sharing_group_ids, location_owner_ids, assigned_user_ids_at_selected_locations, )) return owner_ids
def case_owners(self): """ For unrestricted user :return: user ids for selected user types for selected reporting group ids, returns user_ids belonging to these groups also finds the sharing groups which has any user from the above reporting group selected sharing group ids selected user ids also finds the sharing groups which has any user from the above selected users ids and descendants ids of assigned locations to these users ids and descendants ids of selected locations assigned users at selected locations and their descendants For restricted user :return: selected user ids also finds the sharing groups which has any user from the above selected users ids and descendants ids of assigned locations to these users ids and descendants ids of selected locations assigned users at selected locations and their descendants """ # Get user ids for each user that match the demo_user, admin, # Unknown Users, or All Mobile Workers filters mobile_user_and_group_slugs = self.request.GET.getlist(EMWF.slug) special_owner_ids, selected_sharing_group_ids, selected_reporting_group_users = [], [], [] sharing_group_ids, location_owner_ids, assigned_user_ids_at_selected_locations = [], [], [] if self.request.can_access_all_locations: user_types = EMWF.selected_user_types(mobile_user_and_group_slugs) special_owner_ids = self.get_special_owner_ids( 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=HQUserType.COMMTRACK in user_types, ) # Get group ids for each group that was specified selected_reporting_group_ids = EMWF.selected_reporting_group_ids(mobile_user_and_group_slugs) selected_sharing_group_ids = EMWF.selected_sharing_group_ids(mobile_user_and_group_slugs) # Get user ids for each user in specified reporting groups selected_reporting_group_users = [] if selected_reporting_group_ids: report_group_q = (HQESQuery(index="groups").domain(self.domain) .doc_type("Group") .filter(filters.term("_id", selected_reporting_group_ids)) .fields(["users"])) user_lists = [group["users"] for group in report_group_q.run().hits] selected_reporting_group_users = list(set().union(*user_lists)) # Get user ids for each user that was specifically selected selected_user_ids = EMWF.selected_user_ids(mobile_user_and_group_slugs) # Show cases owned by any selected locations, user locations, or their children loc_ids = set(EMWF.selected_location_ids(mobile_user_and_group_slugs)) if loc_ids: # Get users at selected locations and descendants assigned_user_ids_at_selected_locations = user_ids_at_locations_and_descendants(loc_ids) # Get user ids for each user in specified reporting groups if selected_user_ids: loc_ids.update(get_users_location_ids(self.domain, selected_user_ids)) location_owner_ids = [] if loc_ids: location_owner_ids = SQLLocation.objects.get_locations_and_children_ids(loc_ids) sharing_group_ids = [] if selected_reporting_group_users or selected_user_ids: # Get ids for each sharing group that contains a user from selected_reporting_group_users # OR a user that was specifically selected sharing_group_ids = (HQESQuery(index="groups") .domain(self.domain) .doc_type("Group") .term("case_sharing", True) .term("users", (selected_reporting_group_users + selected_user_ids)) .get_ids()) owner_ids = list(set().union( special_owner_ids, selected_user_ids, selected_sharing_group_ids, selected_reporting_group_users, sharing_group_ids, location_owner_ids, assigned_user_ids_at_selected_locations, )) return owner_ids