Skip to content

Commit

Permalink
computed_settings: Simplify LDAP and SSO conditionals.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <anders@zulip.com>
  • Loading branch information
andersk committed Sep 3, 2020
1 parent 5e2534a commit f302abc
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions zproject/computed_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,20 +965,16 @@ def zulip_path(path: str) -> str:
# SSO AND LDAP SETTINGS
########################################################################

USING_LDAP = "zproject.backends.ZulipLDAPAuthBackend" in AUTHENTICATION_BACKENDS
ONLY_LDAP = AUTHENTICATION_BACKENDS == ("zproject.backends.ZulipLDAPAuthBackend",)
USING_APACHE_SSO = ('zproject.backends.ZulipRemoteUserBackend' in AUTHENTICATION_BACKENDS)
ONLY_SSO = AUTHENTICATION_BACKENDS == ("zproject.backends.ZulipRemoteUserBackend",)

ONLY_LDAP = False
if len(AUTHENTICATION_BACKENDS) == 1 and (AUTHENTICATION_BACKENDS[0] ==
"zproject.backends.ZulipLDAPAuthBackend"):
ONLY_LDAP = True

if len(AUTHENTICATION_BACKENDS) == 1 and (AUTHENTICATION_BACKENDS[0] ==
"zproject.backends.ZulipRemoteUserBackend"):
if ONLY_SSO:
HOME_NOT_LOGGED_IN = "/accounts/login/sso/"
ONLY_SSO = True
else:
HOME_NOT_LOGGED_IN = '/login/'
ONLY_SSO = False

AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipDummyBackend',)

# Redirect to /devlogin/ by default in dev mode
Expand All @@ -988,13 +984,10 @@ def zulip_path(path: str) -> str:

POPULATE_PROFILE_VIA_LDAP = bool(AUTH_LDAP_SERVER_URI)

if POPULATE_PROFILE_VIA_LDAP and \
'zproject.backends.ZulipLDAPAuthBackend' not in AUTHENTICATION_BACKENDS:
if POPULATE_PROFILE_VIA_LDAP and not USING_LDAP:
AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipLDAPUserPopulator',)
else:
POPULATE_PROFILE_VIA_LDAP = (
'zproject.backends.ZulipLDAPAuthBackend' in AUTHENTICATION_BACKENDS or
POPULATE_PROFILE_VIA_LDAP)
POPULATE_PROFILE_VIA_LDAP = USING_LDAP or POPULATE_PROFILE_VIA_LDAP

if POPULATE_PROFILE_VIA_LDAP:
import ldap
Expand All @@ -1014,11 +1007,7 @@ def zulip_path(path: str) -> str:
# The default for REGISTER_LINK_DISABLED is a bit more
# complicated: we want it to be disabled by default for people
# using the LDAP backend that auto-creates users on login.
if (len(AUTHENTICATION_BACKENDS) == 2 and
('zproject.backends.ZulipLDAPAuthBackend' in AUTHENTICATION_BACKENDS)):
REGISTER_LINK_DISABLED = True
else:
REGISTER_LINK_DISABLED = False
REGISTER_LINK_DISABLED = ONLY_LDAP

########################################################################
# SOCIAL AUTHENTICATION SETTINGS
Expand Down

0 comments on commit f302abc

Please sign in to comment.