Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
backends: Update ZulipLDAPAuthBackend to use PreregistrationRealm.
Sahil Batra791c3030ebad
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex 1af5ba5c602..466cb653beb 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -5655,6 +5655,7 @@ class ZulipLDAPTestCase(ZulipTestCase):# method separately, we need to set them manually.self.backend._realm = get_realm("zulip")self.backend._prereg_user = None+ self.backend._prereg_realm = Nonedef setup_subdomain(self, user_profile: UserProfile) -> None:realm = user_profile.realmdiff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 7be2fee92ec..a72d712fa1a 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -461,6 +461,7 @@ def registration_helper(password=password,realm=realm,prereg_user=prereg_user,+ prereg_realm=prereg_realm,return_data=return_data,)if user is None:diff --git a/zproject/backends.py b/zproject/backends.pyindex a17da607716..7e71fd74441 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -97,6 +97,7 @@ from zerver.models import (DomainNotAllowedForRealmError,EmailContainsPlusError,PasswordTooWeakError,+ PreregistrationRealm,PreregistrationUser,Realm,UserProfile,@@ -882,11 +883,13 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):username: str,password: str,realm: Realm,+ prereg_realm: Optional[PreregistrationRealm] = None,prereg_user: Optional[PreregistrationUser] = None,return_data: Optional[Dict[str, Any]] = None,) -> Optional[UserProfile]:self._realm = realmself._prereg_user = prereg_user+ self._prereg_realm = prereg_realmif not ldap_auth_enabled(realm):return None@@ -992,19 +995,21 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):opts: Dict[str, Any] = {}if self._prereg_user:invited_as = self._prereg_user.invited_as- realm_creation = self._prereg_user.realm_creationopts["prereg_user"] = self._prereg_useropts["role"] = invited_as- if realm_creation:- opts["role"] = UserProfile.ROLE_REALM_OWNER-- opts["realm_creation"] = realm_creation+ opts["realm_creation"] = False# TODO: Ideally, we should add a mechanism for the user# entering which default stream groups they've selected in# the LDAP flow.opts["default_stream_groups"] = []+ if self._prereg_realm:+ opts["prereg_realm"] = self._prereg_realm+ opts["realm_creation"] = True+ opts["role"] = UserProfile.ROLE_REALM_OWNER+ opts["default_stream_groups"] = []+user_profile = do_create_user(username, None, self._realm, full_name, acting_user=None, **opts)