def do_scrub_realm(realm: Realm, acting_user: Optional[UserProfile]=None) -> None:
    users = UserProfile.objects.filter(realm=realm)
    for user in users:
        do_delete_messages_by_sender(user)
        do_delete_avatar_image(user, acting_user=acting_user)
        user.full_name = f'Scrubbed {generate_key()[:15]}'
        scrubbed_email = f'scrubbed-{generate_key()[:15]}@{realm.host}'
        user.email = scrubbed_email
        user.delivery_email = scrubbed_email
        user.save(update_fields=['full_name', 'email', 'delivery_email'])
    do_remove_realm_custom_profile_fields(realm)
    Attachment.objects.filter(realm=realm).delete()
    RealmAuditLog.objects.create(realm=realm, event_time=timezone_now(), acting_user=acting_user, event_type=RealmAuditLog.REALM_SCRUBBED)
def do_scrub_realm(realm: Realm, acting_user: Optional[UserProfile]=None) -> None:
    users = UserProfile.objects.filter(realm=realm)
    for user in users:
        do_delete_messages_by_sender(user)
        do_delete_avatar_image(user, acting_user=acting_user)
        user.full_name = f'Scrubbed {generate_key()[:15]}'
        scrubbed_email = f'scrubbed-{generate_key()[:15]}@{realm.host}'
        user.email = scrubbed_email
        user.delivery_email = scrubbed_email
        user.save(update_fields=['full_name', 'email', 'delivery_email'])
    do_remove_realm_custom_profile_fields(realm)
    Attachment.objects.filter(realm=realm).delete()
    RealmAuditLog.objects.create(realm=realm, event_time=timezone_now(), acting_user=acting_user, event_type=RealmAuditLog.REALM_SCRUBBED)