def obj_get_list(self, bundle, **kwargs): domain = kwargs['domain'] user_ids_username_pairs = get_all_user_id_username_pairs_by_domain( domain) results = [ UserInfo(user_id=user_pair[0], user_name=raw_username(user_pair[1])) for user_pair in user_ids_username_pairs ] return results
def get_duplicate_users(domain): by_username = defaultdict(list) for user_id, username in get_all_user_id_username_pairs_by_domain(domain, include_web_users=False): by_username[username].append(user_id) dupes = {} for username, user_ids in by_username.items(): if len(user_ids) > 1: dupes[username] = user_ids return dupes
def obj_get_list(self, bundle, **kwargs): domain = kwargs['domain'] couch_user = CouchUser.from_django_user(bundle.request.user) if not domain_has_privilege(domain, privileges.ZAPIER_INTEGRATION) or not couch_user.is_member_of(domain): raise ImmediateHttpResponse( HttpForbidden('You are not allowed to get list of usernames for this domain') ) user_ids_username_pairs = get_all_user_id_username_pairs_by_domain(domain) results = [UserInfo(user_id=user_pair[0], user_name=raw_username(user_pair[1])) for user_pair in user_ids_username_pairs] return results
def obj_get_list(self, bundle, **kwargs): domain = kwargs['domain'] couch_user = CouchUser.from_django_user(bundle.request.user) if not domain_has_privilege(domain, privileges.ZAPIER_INTEGRATION) or not couch_user.is_member_of(domain): raise ImmediateHttpResponse( HttpForbidden('You are not allowed to get list of usernames for this domain') ) user_ids_username_pairs = get_all_user_id_username_pairs_by_domain(domain) results = [UserInfo(user_id=user_pair[0], user_name=raw_username(user_pair[1])) for user_pair in user_ids_username_pairs] return results
def get_filters(self, domain_name): """ :return: A generator of filters each filtering for at most 500 users. """ from corehq.apps.users.dbaccessors.all_commcare_users import get_all_usernames_by_domain from corehq.apps.users.dbaccessors.all_commcare_users import get_all_user_id_username_pairs_by_domain if self.user_ids: usernames = [ username for user_id, username in get_all_user_id_username_pairs_by_domain( domain_name, include_web_users=False) if user_id in self.user_ids ] else: usernames = get_all_usernames_by_domain(domain_name) for chunk in chunked(usernames, 500): filter = Q() for username in chunk: filter |= Q(username__iexact=username) yield filter
def handle(self, domain, output_dir, *args, **kwargs): domain = domain all_users = get_all_user_id_username_pairs_by_domain( domain, include_web_users=False, include_mobile_users=True) all_dashboard_usernames = { uname for id, uname in all_users if dashboard_uname_rx.match(uname) } end_date = datetime.utcnow() start_date_week = end_date - timedelta(days=7) not_logged_in_week = get_dashboard_users_not_logged_in( start_date_week, end_date, all_dashboard_usernames) week_file_name = 'dashboard_users_not_logged_in_{:%Y-%m-%d}_to_{:%Y-%m-%d}.csv'.format( start_date_week, end_date) output(not_logged_in_week, os.path.join(output_dir, week_file_name)) start_date_month = end_date - timedelta(days=30) not_logged_in_month = get_dashboard_users_not_logged_in( start_date_month, end_date, all_dashboard_usernames) month_file_name = 'dashboard_users_not_logged_in_{:%Y-%m-%d}_to_{:%Y-%m-%d}.csv'.format( start_date_month, end_date) output(not_logged_in_month, os.path.join(output_dir, month_file_name))
def get_dashboard_users_not_logged_in(start_date, end_date, domain='icds-cas'): all_users = get_all_user_id_username_pairs_by_domain( domain, include_web_users=False, include_mobile_users=True) dashboard_uname_rx = re.compile(r'^\d*\.[a-zA-Z]*@.*') dashboard_usernames = { uname for id, uname in all_users if dashboard_uname_rx.match(uname) } logged_in = ICDSAuditEntryRecord.objects.filter( time_of_use__gte=start_date, time_of_use__lt=end_date).values_list('username', flat=True) logged_in_dashboard_users = { u for u in logged_in if dashboard_uname_rx.match(u) } not_logged_in = dashboard_usernames - logged_in_dashboard_users return not_logged_in