mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	export: Export file images for single users.
We don't have automated test coverage on this yet,
but below are the results from manual testing.
Note that we include the realm icon and logo even
though they were not created by Cordelia.
    ./manage.py export_single_user cordelia@zulip.com
    $ (cd /tmp/zulip-export-4v3mo802/ && find .)
    .
    ./emoji
    ./emoji/2
    ./emoji/2/emoji
    ./emoji/2/emoji/images
    ./emoji/2/emoji/images/3.jpg
    ./emoji/records.json
    ./messages-000001.json
    ./realm_icons
    ./realm_icons/2
    ./realm_icons/2/night_logo.original
    ./realm_icons/2/night_logo.png
    ./realm_icons/2/icon.png
    ./realm_icons/2/icon.original
    ./realm_icons/records.json
    ./avatars
    ./avatars/2
    ./avatars/2/c5125af0447f4d66ce34c1b32eac75ac27ebe0e7.original
    ./avatars/2/c5125af0447f4d66ce34c1b32eac75ac27ebe0e7.png
    ./avatars/records.json
    ./uploads
    ./uploads/2
    ./uploads/2/68
    ./uploads/2/68/xyEkC5dTIp8m42_6HJ3kBfdt
    ./uploads/2/68/xyEkC5dTIp8m42_6HJ3kBfdt/denver.jpg
    ./uploads/2/96
    ./uploads/2/96/ol5WE6RTUntvuPDSpJUrYTim
    ./uploads/2/96/ol5WE6RTUntvuPDSpJUrYTim/denver.jpg
    ./uploads/records.json
    ./user.json
			
			
This commit is contained in:
		@@ -1270,7 +1270,9 @@ def write_message_partial_for_query(
 | 
			
		||||
    return dump_file_id
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
			
		||||
def export_uploads_and_avatars(
 | 
			
		||||
    realm: Realm, *, user: Optional[UserProfile], output_dir: Path
 | 
			
		||||
) -> None:
 | 
			
		||||
    uploads_output_dir = os.path.join(output_dir, "uploads")
 | 
			
		||||
    avatars_output_dir = os.path.join(output_dir, "avatars")
 | 
			
		||||
    realm_icons_output_dir = os.path.join(output_dir, "realm_icons")
 | 
			
		||||
@@ -1285,10 +1287,16 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
			
		||||
        if not os.path.exists(dir_path):
 | 
			
		||||
            os.makedirs(dir_path)
 | 
			
		||||
 | 
			
		||||
    handle_system_bots = True
 | 
			
		||||
    users = list(UserProfile.objects.filter(realm=realm))
 | 
			
		||||
    attachments = list(Attachment.objects.filter(realm_id=realm.id))
 | 
			
		||||
    realm_emojis = list(RealmEmoji.objects.filter(realm_id=realm.id))
 | 
			
		||||
    if user is None:
 | 
			
		||||
        handle_system_bots = True
 | 
			
		||||
        users = list(UserProfile.objects.filter(realm=realm))
 | 
			
		||||
        attachments = list(Attachment.objects.filter(realm_id=realm.id))
 | 
			
		||||
        realm_emojis = list(RealmEmoji.objects.filter(realm_id=realm.id))
 | 
			
		||||
    else:
 | 
			
		||||
        handle_system_bots = False
 | 
			
		||||
        users = [user]
 | 
			
		||||
        attachments = list(Attachment.objects.filter(owner_id=user.id))
 | 
			
		||||
        realm_emojis = list(RealmEmoji.objects.filter(author_id=user.id))
 | 
			
		||||
 | 
			
		||||
    if settings.LOCAL_UPLOADS_DIR:
 | 
			
		||||
        # Small installations and developers will usually just store files locally.
 | 
			
		||||
@@ -1742,7 +1750,7 @@ def do_export_realm(
 | 
			
		||||
    sanity_check_output(response)
 | 
			
		||||
 | 
			
		||||
    logging.info("Exporting uploaded files and avatars")
 | 
			
		||||
    export_uploads_and_avatars(realm, output_dir)
 | 
			
		||||
    export_uploads_and_avatars(realm, user=None, output_dir=output_dir)
 | 
			
		||||
 | 
			
		||||
    # We (sort of) export zerver_message rows here.  We write
 | 
			
		||||
    # them to .partial files that are subsequently fleshed out
 | 
			
		||||
@@ -1861,6 +1869,9 @@ def do_export_user(user_profile: UserProfile, output_dir: Path) -> None:
 | 
			
		||||
    logging.info("Exporting messages")
 | 
			
		||||
    export_messages_single_user(user_profile, output_dir)
 | 
			
		||||
 | 
			
		||||
    logging.info("Exporting images")
 | 
			
		||||
    export_uploads_and_avatars(user_profile.realm, user=user_profile, output_dir=output_dir)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def export_single_user(user_profile: UserProfile, response: TableData) -> None:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user