Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
data_import: Fix bot email address de-duplication.
Alex Vandiver2e50ead9d14f
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.pyindex 5d6af9b8920..00a54d00dfc 100755--- a/zerver/data_import/slack.py+++ b/zerver/data_import/slack.py@@ -78,14 +78,13 @@ class SlackBotEmail:else:raise AssertionError("Could not identify bot type")- email = slack_bot_name.replace("Bot", "").replace(" ", "") + f"-bot@{domain_name}"+ email = slack_bot_name.replace("Bot", "").replace(" ", "").lower() + f"-bot@{domain_name}"if email in cls.duplicate_email_count:+ cls.duplicate_email_count[email] += 1email_prefix, email_suffix = email.split("@")- email_prefix += cls.duplicate_email_count[email]+ email_prefix += "-" + str(cls.duplicate_email_count[email])email = "@".join([email_prefix, email_suffix])- # Increment the duplicate email count- cls.duplicate_email_count[email] += 1else:cls.duplicate_email_count[email] = 1diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.pyindex 1ff2b72445e..fa042c51bb9 100644--- a/zerver/tests/test_slack_importer.py+++ b/zerver/tests/test_slack_importer.py@@ -25,6 +25,7 @@ from zerver.data_import.slack import (AddedChannelsT,AddedMPIMsT,DMMembersT,+ SlackBotEmail,channel_message_to_zerver_message,channels_to_zerver_stream,convert_slack_workspace_messages,@@ -1213,3 +1214,38 @@ class SlackImporter(ZulipTestCase):self.assertEqual(uploads_list[0]["s3_path"], image_path)self.assertEqual(uploads_list[0]["realm_id"], realm_id)self.assertEqual(uploads_list[0]["user_profile_email"], "[email protected]")++ def test_bot_duplicates(self) -> None:+ self.assertEqual(+ SlackBotEmail.get_email(+ {"real_name_normalized": "Real Bot", "bot_id": "foo"}, "example.com"+ ),+ "[email protected]",+ )++ # SlackBotEmail keeps state -- doing it again appends a "2", "3", etc+ self.assertEqual(+ SlackBotEmail.get_email(+ {"real_name_normalized": "Real Bot", "bot_id": "bar"}, "example.com"+ ),+ "[email protected]",+ )+ self.assertEqual(+ SlackBotEmail.get_email(+ {"real_name_normalized": "Real Bot", "bot_id": "baz"}, "example.com"+ ),+ "[email protected]",+ )++ # But caches based on the bot_id+ self.assertEqual(+ SlackBotEmail.get_email(+ {"real_name_normalized": "Real Bot", "bot_id": "foo"}, "example.com"+ ),+ "[email protected]",+ )++ self.assertEqual(+ SlackBotEmail.get_email({"first_name": "Other Name", "bot_id": "other"}, "example.com"),+ "[email protected]",+ )