Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
gitter: Make imported Realm start with only GitHub auth enabled.
Mateusz Manderad3504069910d
diff --git a/zerver/data_import/gitter.py b/zerver/data_import/gitter.pyindex a86ea5f014a..c073ac4c054 100644--- a/zerver/data_import/gitter.py+++ b/zerver/data_import/gitter.py@@ -27,6 +27,7 @@ from zerver.data_import.import_util import ()from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZEfrom zerver.models import Recipient, UserProfile+from zproject.backends import GitHubAuthBackend# stubsGitterDataT = List[Dict[str, Any]]@@ -46,6 +47,20 @@ def gitter_workspace_to_realm("""NOW = float(timezone_now().timestamp())zerver_realm: List[ZerverFieldsT] = build_zerver_realm(realm_id, realm_subdomain, NOW, "Gitter")++ # Users will have GitHub's generated noreply email addresses so their only way to log in+ # at first is via GitHub. So we set GitHub to be the only authentication method enabled+ # default to avoid user confusion.+ assert len(zerver_realm) == 1+ authentication_methods = [+ (auth_method[0], False)+ if auth_method[0] != GitHubAuthBackend.auth_backend_name+ else (auth_method[0], True)+ for auth_method in zerver_realm[0]["authentication_methods"]+ ]++ zerver_realm[0]["authentication_methods"] = authentication_methods+realm = build_realm(zerver_realm, realm_id, domain_name)zerver_userprofile, avatars, user_map = build_userprofile(int(NOW), domain_name, gitter_data)diff --git a/zerver/tests/test_gitter_importer.py b/zerver/tests/test_gitter_importer.pyindex 4f51b8ebec6..7ceaef45f80 100644--- a/zerver/tests/test_gitter_importer.py+++ b/zerver/tests/test_gitter_importer.py@@ -8,7 +8,8 @@ import orjsonfrom zerver.data_import.gitter import do_convert_data, get_usermentionsfrom zerver.lib.import_realm import do_import_realmfrom zerver.lib.test_classes import ZulipTestCase-from zerver.models import Message, UserProfile, get_realm+from zerver.models import Message, Realm, UserProfile, get_realm+from zproject.backends import GitHubAuthBackend, auth_enabled_helper, github_auth_enabledclass GitterImporter(ZulipTestCase):@@ -127,6 +128,13 @@ class GitterImporter(ZulipTestCase):for message in messages:self.assertIsNotNone(message.rendered_content, None)+ self.assertTrue(github_auth_enabled(realm))+ for auth_backend_name in Realm.AUTHENTICATION_FLAGS:+ if auth_backend_name == GitHubAuthBackend.auth_backend_name:+ continue++ self.assertFalse(auth_enabled_helper([auth_backend_name], realm))+def test_get_usermentions(self) -> None:user_map = {"57124a4": 3, "57124b4": 5, "57124c4": 8}user_short_name_to_full_name = {