mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 01:16:19 +00:00
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:
committed by
Tim Abbott
parent
d5b450c1e0
commit
d350406991
@@ -27,6 +27,7 @@ from zerver.data_import.import_util import (
|
|||||||
)
|
)
|
||||||
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
|
from zerver.lib.export import MESSAGE_BATCH_CHUNK_SIZE
|
||||||
from zerver.models import Recipient, UserProfile
|
from zerver.models import Recipient, UserProfile
|
||||||
|
from zproject.backends import GitHubAuthBackend
|
||||||
|
|
||||||
# stubs
|
# stubs
|
||||||
GitterDataT = List[Dict[str, Any]]
|
GitterDataT = List[Dict[str, Any]]
|
||||||
@@ -46,6 +47,20 @@ def gitter_workspace_to_realm(
|
|||||||
"""
|
"""
|
||||||
NOW = float(timezone_now().timestamp())
|
NOW = float(timezone_now().timestamp())
|
||||||
zerver_realm: List[ZerverFieldsT] = build_zerver_realm(realm_id, realm_subdomain, NOW, "Gitter")
|
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)
|
realm = build_realm(zerver_realm, realm_id, domain_name)
|
||||||
|
|
||||||
zerver_userprofile, avatars, user_map = build_userprofile(int(NOW), domain_name, gitter_data)
|
zerver_userprofile, avatars, user_map = build_userprofile(int(NOW), domain_name, gitter_data)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import orjson
|
|||||||
from zerver.data_import.gitter import do_convert_data, get_usermentions
|
from zerver.data_import.gitter import do_convert_data, get_usermentions
|
||||||
from zerver.lib.import_realm import do_import_realm
|
from zerver.lib.import_realm import do_import_realm
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
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):
|
class GitterImporter(ZulipTestCase):
|
||||||
@@ -127,6 +128,13 @@ class GitterImporter(ZulipTestCase):
|
|||||||
for message in messages:
|
for message in messages:
|
||||||
self.assertIsNotNone(message.rendered_content, None)
|
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:
|
def test_get_usermentions(self) -> None:
|
||||||
user_map = {"57124a4": 3, "57124b4": 5, "57124c4": 8}
|
user_map = {"57124a4": 3, "57124b4": 5, "57124c4": 8}
|
||||||
user_short_name_to_full_name = {
|
user_short_name_to_full_name = {
|
||||||
|
|||||||
Reference in New Issue
Block a user