From b383f5ca5d004cf7f3daac3532fa41b0e3a3f8f1 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 10 Aug 2016 17:39:21 -0700 Subject: [PATCH] export: Extract fetch_user_profile_cross_realm(). --- zerver/lib/export.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/zerver/lib/export.py b/zerver/lib/export.py index 76e58c6a94..eca4f43104 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -180,16 +180,12 @@ def export_with_admin_auth(realm, response, include_invite_only=True): # type: (Any, **Any) -> Any return model.objects.filter(realm=realm, **kwargs) + cross_realm_context = {'realm': realm} + response['zerver_userprofile'] = [model_to_dict(x, exclude=["password", "api_key"]) for x in filter_by_realm(UserProfile)] - if realm.domain == "zulip.com": - response['zerver_userprofile_crossrealm'] = [] - else: - response['zerver_userprofile_crossrealm'] = [dict(email=x.email, id=x.id) for x in [ - get_user_profile_by_email(settings.NOTIFICATION_BOT), - get_user_profile_by_email(settings.EMAIL_GATEWAY_BOT), - get_user_profile_by_email(settings.WELCOME_BOT), - ]] + fetch_user_profile_cross_realm(response, cross_realm_context) + floatify_datetime_fields(response, 'zerver_userprofile') user_profile_ids = get_primary_ids(response['zerver_userprofile']) @@ -248,6 +244,20 @@ def export_with_admin_auth(realm, response, include_invite_only=True): response["zerver_attachment"] = make_raw(attachment_query) floatify_datetime_fields(response, 'zerver_attachment') +def fetch_user_profile_cross_realm(response, context): + # type: (TableData, Context) -> None + + realm = context['realm'] + + if realm.domain == "zulip.com": + response['zerver_userprofile_crossrealm'] = [] + else: + response['zerver_userprofile_crossrealm'] = [dict(email=x.email, id=x.id) for x in [ + get_user_profile_by_email(settings.NOTIFICATION_BOT), + get_user_profile_by_email(settings.EMAIL_GATEWAY_BOT), + get_user_profile_by_email(settings.WELCOME_BOT), + ]] + def fetch_huddle_objects(response, context): # type: (TableData, Context) -> Tuple[List[Record], List[Record]]