mirror of https://github.com/zulip/zulip.git
backends: Update ZulipLDAPAuthBackend to use PreregistrationRealm.
This commit updates ZulipLDAPAuthBackend to use the recently added PreregistrationRealm when creating realms with LDAP used as authentication method.
This commit is contained in:
parent
e60b6b68ea
commit
791c3030eb
|
@ -5655,6 +5655,7 @@ class ZulipLDAPTestCase(ZulipTestCase):
|
||||||
# method separately, we need to set them manually.
|
# method separately, we need to set them manually.
|
||||||
self.backend._realm = get_realm("zulip")
|
self.backend._realm = get_realm("zulip")
|
||||||
self.backend._prereg_user = None
|
self.backend._prereg_user = None
|
||||||
|
self.backend._prereg_realm = None
|
||||||
|
|
||||||
def setup_subdomain(self, user_profile: UserProfile) -> None:
|
def setup_subdomain(self, user_profile: UserProfile) -> None:
|
||||||
realm = user_profile.realm
|
realm = user_profile.realm
|
||||||
|
|
|
@ -461,6 +461,7 @@ def registration_helper(
|
||||||
password=password,
|
password=password,
|
||||||
realm=realm,
|
realm=realm,
|
||||||
prereg_user=prereg_user,
|
prereg_user=prereg_user,
|
||||||
|
prereg_realm=prereg_realm,
|
||||||
return_data=return_data,
|
return_data=return_data,
|
||||||
)
|
)
|
||||||
if user is None:
|
if user is None:
|
||||||
|
|
|
@ -97,6 +97,7 @@ from zerver.models import (
|
||||||
DomainNotAllowedForRealmError,
|
DomainNotAllowedForRealmError,
|
||||||
EmailContainsPlusError,
|
EmailContainsPlusError,
|
||||||
PasswordTooWeakError,
|
PasswordTooWeakError,
|
||||||
|
PreregistrationRealm,
|
||||||
PreregistrationUser,
|
PreregistrationUser,
|
||||||
Realm,
|
Realm,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
|
@ -882,11 +883,13 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
||||||
username: str,
|
username: str,
|
||||||
password: str,
|
password: str,
|
||||||
realm: Realm,
|
realm: Realm,
|
||||||
|
prereg_realm: Optional[PreregistrationRealm] = None,
|
||||||
prereg_user: Optional[PreregistrationUser] = None,
|
prereg_user: Optional[PreregistrationUser] = None,
|
||||||
return_data: Optional[Dict[str, Any]] = None,
|
return_data: Optional[Dict[str, Any]] = None,
|
||||||
) -> Optional[UserProfile]:
|
) -> Optional[UserProfile]:
|
||||||
self._realm = realm
|
self._realm = realm
|
||||||
self._prereg_user = prereg_user
|
self._prereg_user = prereg_user
|
||||||
|
self._prereg_realm = prereg_realm
|
||||||
if not ldap_auth_enabled(realm):
|
if not ldap_auth_enabled(realm):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -992,19 +995,21 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
||||||
opts: Dict[str, Any] = {}
|
opts: Dict[str, Any] = {}
|
||||||
if self._prereg_user:
|
if self._prereg_user:
|
||||||
invited_as = self._prereg_user.invited_as
|
invited_as = self._prereg_user.invited_as
|
||||||
realm_creation = self._prereg_user.realm_creation
|
|
||||||
opts["prereg_user"] = self._prereg_user
|
opts["prereg_user"] = self._prereg_user
|
||||||
|
|
||||||
opts["role"] = invited_as
|
opts["role"] = invited_as
|
||||||
if realm_creation:
|
opts["realm_creation"] = False
|
||||||
opts["role"] = UserProfile.ROLE_REALM_OWNER
|
|
||||||
|
|
||||||
opts["realm_creation"] = realm_creation
|
|
||||||
# TODO: Ideally, we should add a mechanism for the user
|
# TODO: Ideally, we should add a mechanism for the user
|
||||||
# entering which default stream groups they've selected in
|
# entering which default stream groups they've selected in
|
||||||
# the LDAP flow.
|
# the LDAP flow.
|
||||||
opts["default_stream_groups"] = []
|
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(
|
user_profile = do_create_user(
|
||||||
username, None, self._realm, full_name, acting_user=None, **opts
|
username, None, self._realm, full_name, acting_user=None, **opts
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue