gitter: Make imported Realm start with only GitHub auth enabled.

Users will only be able to login via GitHub, because imported users
get GitHub's generated noreply email addresses - so this should be the
only auth method enabled at first, to avoid confusion.
This commit is contained in:
Mateusz Mandera
2022-08-26 14:43:46 +02:00
committed by Tim Abbott
parent d5b450c1e0
commit d350406991
2 changed files with 24 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ from zerver.data_import.import_util import (
)
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
from zerver.models import Recipient, UserProfile
from zproject.backends import GitHubAuthBackend
# stubs
GitterDataT = 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)

View File

@@ -8,7 +8,8 @@ import orjson
from zerver.data_import.gitter import do_convert_data, get_usermentions
from zerver.lib.import_realm import do_import_realm
from 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_enabled
class 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 = {