Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

slack_importer: Use `build_user_profile`.

PieterCKdb7182617924
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 1a937584205..4545eb18f2f 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -33,6 +33,7 @@ from zerver.data_import.import_util import (
build_recipient,
build_stream,
build_subscription,
+ build_user_profile,
build_usermessages,
build_zerver_realm,
create_converted_data_files,
@@ -357,25 +358,22 @@ def users_to_zerver_userprofile(
else:
bot_type = None
- userprofile = UserProfile(
+ userprofile_dict = build_user_profile(
+ avatar_source=avatar_source,
+ date_joined=timestamp,
+ delivery_email=email,
+ email=email,
full_name=get_user_full_name(user),
+ id=user_id,
is_active=not user.get("deleted", False) and not user["is_mirror_dummy"],
+ role=role,
is_mirror_dummy=user["is_mirror_dummy"],
- id=user_id,
- email=email,
- delivery_email=email,
- avatar_source=avatar_source,
+ realm_id=realm_id,
+ short_name=user["name"],
+ timezone=timezone,
is_bot=is_bot,
- role=role,
bot_type=bot_type,
- date_joined=timestamp,
- timezone=timezone,
- last_login=timestamp,
- is_imported_stub=True,
)
- userprofile_dict = model_to_dict(userprofile)
- # Set realm id separately as the corresponding realm is not yet a Realm model instance
- userprofile_dict["realm"] = realm_id
zerver_userprofile.append(userprofile_dict)
slack_user_id_to_zulip_user_id[slack_user_id] = user_id
diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py
index 73feedb74a0..7e00b4ed7dc 100644
--- a/zerver/tests/test_slack_importer.py
+++ b/zerver/tests/test_slack_importer.py
@@ -771,6 +771,8 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[0]["email"], "[email protected]")
self.assertEqual(zerver_userprofile[0]["full_name"], "John Doe")
self.assertEqual(zerver_userprofile[0]["is_imported_stub"], True)
+ self.assertEqual(zerver_userprofile[0]["short_name"], "john")
+ self.assertEqual(zerver_userprofile[0]["last_login"], None)
self.assertEqual(
zerver_userprofile[1]["id"], test_slack_user_id_to_zulip_user_id["U0CBK5KAT"]