mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	export: Add handle_system_bots flag.
We will set this to False for single-user exports.
This commit is contained in:
		@@ -1285,6 +1285,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
        if not os.path.exists(dir_path):
 | 
					        if not os.path.exists(dir_path):
 | 
				
			||||||
            os.makedirs(dir_path)
 | 
					            os.makedirs(dir_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    handle_system_bots = True
 | 
				
			||||||
    users = list(UserProfile.objects.filter(realm=realm))
 | 
					    users = list(UserProfile.objects.filter(realm=realm))
 | 
				
			||||||
    attachments = list(Attachment.objects.filter(realm_id=realm.id))
 | 
					    attachments = list(Attachment.objects.filter(realm_id=realm.id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1301,6 +1302,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
            local_dir=os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars"),
 | 
					            local_dir=os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars"),
 | 
				
			||||||
            output_dir=avatars_output_dir,
 | 
					            output_dir=avatars_output_dir,
 | 
				
			||||||
            users=users,
 | 
					            users=users,
 | 
				
			||||||
 | 
					            handle_system_bots=handle_system_bots,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        export_emoji_from_local(
 | 
					        export_emoji_from_local(
 | 
				
			||||||
            realm,
 | 
					            realm,
 | 
				
			||||||
@@ -1321,6 +1323,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        export_files_from_s3(
 | 
					        export_files_from_s3(
 | 
				
			||||||
            realm,
 | 
					            realm,
 | 
				
			||||||
 | 
					            handle_system_bots=handle_system_bots,
 | 
				
			||||||
            flavor="upload",
 | 
					            flavor="upload",
 | 
				
			||||||
            bucket_name=settings.S3_AUTH_UPLOADS_BUCKET,
 | 
					            bucket_name=settings.S3_AUTH_UPLOADS_BUCKET,
 | 
				
			||||||
            object_prefix=f"{realm.id}/",
 | 
					            object_prefix=f"{realm.id}/",
 | 
				
			||||||
@@ -1337,6 +1340,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        export_files_from_s3(
 | 
					        export_files_from_s3(
 | 
				
			||||||
            realm,
 | 
					            realm,
 | 
				
			||||||
 | 
					            handle_system_bots=handle_system_bots,
 | 
				
			||||||
            flavor="avatar",
 | 
					            flavor="avatar",
 | 
				
			||||||
            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
					            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
				
			||||||
            object_prefix=f"{realm.id}/",
 | 
					            object_prefix=f"{realm.id}/",
 | 
				
			||||||
@@ -1347,6 +1351,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        export_files_from_s3(
 | 
					        export_files_from_s3(
 | 
				
			||||||
            realm,
 | 
					            realm,
 | 
				
			||||||
 | 
					            handle_system_bots=handle_system_bots,
 | 
				
			||||||
            flavor="emoji",
 | 
					            flavor="emoji",
 | 
				
			||||||
            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
					            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
				
			||||||
            object_prefix=f"{realm.id}/emoji/images/",
 | 
					            object_prefix=f"{realm.id}/emoji/images/",
 | 
				
			||||||
@@ -1357,6 +1362,7 @@ def export_uploads_and_avatars(realm: Realm, output_dir: Path) -> None:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        export_files_from_s3(
 | 
					        export_files_from_s3(
 | 
				
			||||||
            realm,
 | 
					            realm,
 | 
				
			||||||
 | 
					            handle_system_bots=handle_system_bots,
 | 
				
			||||||
            flavor="realm_icon_or_logo",
 | 
					            flavor="realm_icon_or_logo",
 | 
				
			||||||
            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
					            bucket_name=settings.S3_AVATAR_BUCKET,
 | 
				
			||||||
            object_prefix=f"{realm.id}/realm/",
 | 
					            object_prefix=f"{realm.id}/realm/",
 | 
				
			||||||
@@ -1437,6 +1443,7 @@ def _save_s3_object_to_file(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def export_files_from_s3(
 | 
					def export_files_from_s3(
 | 
				
			||||||
    realm: Realm,
 | 
					    realm: Realm,
 | 
				
			||||||
 | 
					    handle_system_bots: bool,
 | 
				
			||||||
    flavor: str,
 | 
					    flavor: str,
 | 
				
			||||||
    bucket_name: str,
 | 
					    bucket_name: str,
 | 
				
			||||||
    object_prefix: str,
 | 
					    object_prefix: str,
 | 
				
			||||||
@@ -1454,7 +1461,7 @@ def export_files_from_s3(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    email_gateway_bot: Optional[UserProfile] = None
 | 
					    email_gateway_bot: Optional[UserProfile] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if settings.EMAIL_GATEWAY_BOT is not None:
 | 
					    if handle_system_bots and settings.EMAIL_GATEWAY_BOT is not None:
 | 
				
			||||||
        internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
 | 
					        internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
 | 
				
			||||||
        email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
 | 
					        email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
 | 
				
			||||||
        user_ids.add(email_gateway_bot.id)
 | 
					        user_ids.add(email_gateway_bot.id)
 | 
				
			||||||
@@ -1547,18 +1554,24 @@ def export_uploads_from_local(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def export_avatars_from_local(
 | 
					def export_avatars_from_local(
 | 
				
			||||||
    realm: Realm, local_dir: Path, output_dir: Path, users: List[UserProfile]
 | 
					    realm: Realm,
 | 
				
			||||||
 | 
					    local_dir: Path,
 | 
				
			||||||
 | 
					    output_dir: Path,
 | 
				
			||||||
 | 
					    users: List[UserProfile],
 | 
				
			||||||
 | 
					    handle_system_bots: bool,
 | 
				
			||||||
) -> None:
 | 
					) -> None:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    count = 0
 | 
					    count = 0
 | 
				
			||||||
    records = []
 | 
					    records = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if handle_system_bots:
 | 
				
			||||||
        internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
 | 
					        internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
 | 
				
			||||||
        users += [
 | 
					        users += [
 | 
				
			||||||
            get_system_bot(settings.NOTIFICATION_BOT, internal_realm.id),
 | 
					            get_system_bot(settings.NOTIFICATION_BOT, internal_realm.id),
 | 
				
			||||||
            get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id),
 | 
					            get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id),
 | 
				
			||||||
            get_system_bot(settings.WELCOME_BOT, internal_realm.id),
 | 
					            get_system_bot(settings.WELCOME_BOT, internal_realm.id),
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for user in users:
 | 
					    for user in users:
 | 
				
			||||||
        if user.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR:
 | 
					        if user.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR:
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user