settings: Add CUSTOM_HOME_NOT_LOGGED_IN for type narrowing.

django-stubs dynamically collects the type annotation for us from the
settings, acknowledging mypy that `HOME_NOT_LOGGED_IN` is an
`Optional[str]`. Type narrowing with assertions does not play well with
the default value of the decorator, so we define the same setting
variable with a different name as `CUSTOM_HOME_NOT_LOGGED_IN` to bypass
this restriction.

Filed python/mypy#13087 to track this issue.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-07-07 20:27:56 -04:00
committed by Tim Abbott
parent 44f5c1cb33
commit 2e248cdbec
3 changed files with 12 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ from .configured_settings import (
AUTH_LDAP_SERVER_URI,
AUTHENTICATION_BACKENDS,
CAMO_URI,
CUSTOM_HOME_NOT_LOGGED_IN,
DEBUG,
DEBUG_ERROR_REPORTING,
EMAIL_BACKEND,
@@ -38,7 +39,6 @@ from .configured_settings import (
EXTERNAL_URI_SCHEME,
EXTRA_INSTALLED_APPS,
GOOGLE_OAUTH2_CLIENT_ID,
HOME_NOT_LOGGED_IN,
INVITATION_LINK_VALIDITY_DAYS,
IS_DEV_DROPLET,
LOCAL_UPLOADS_DIR,
@@ -1039,10 +1039,14 @@ ONLY_LDAP = AUTHENTICATION_BACKENDS == ("zproject.backends.ZulipLDAPAuthBackend"
USING_APACHE_SSO = "zproject.backends.ZulipRemoteUserBackend" in AUTHENTICATION_BACKENDS
ONLY_SSO = AUTHENTICATION_BACKENDS == ("zproject.backends.ZulipRemoteUserBackend",)
if HOME_NOT_LOGGED_IN is None:
if ONLY_SSO:
if CUSTOM_HOME_NOT_LOGGED_IN is not None:
# We import this with a different name to avoid a mypy bug with
# type-narrowed default parameter values.
# https://github.com/python/mypy/issues/13087
HOME_NOT_LOGGED_IN = CUSTOM_HOME_NOT_LOGGED_IN
elif ONLY_SSO:
HOME_NOT_LOGGED_IN = "/accounts/login/sso/"
else:
else:
HOME_NOT_LOGGED_IN = "/login/"
AUTHENTICATION_BACKENDS += ("zproject.backends.ZulipDummyBackend",)

View File

@@ -106,7 +106,7 @@ SOCIAL_AUTH_SYNC_CUSTOM_ATTRS_DICT: Dict[str, Dict[str, Dict[str, str]]] = {}
# Other auth
SSO_APPEND_DOMAIN: Optional[str] = None
HOME_NOT_LOGGED_IN: Optional[str] = None
CUSTOM_HOME_NOT_LOGGED_IN: Optional[str] = None
VIDEO_ZOOM_CLIENT_ID = get_secret("video_zoom_client_id", development_only=True)
VIDEO_ZOOM_CLIENT_SECRET = get_secret("video_zoom_client_secret")

View File

@@ -79,7 +79,7 @@ WEB_PUBLIC_STREAMS_ENABLED = True
INVITES_MIN_USER_AGE_DAYS = 0
# Redirect to /devlogin/ by default in dev mode
HOME_NOT_LOGGED_IN = "/devlogin/"
CUSTOM_HOME_NOT_LOGGED_IN = "/devlogin/"
LOGIN_URL = "/devlogin/"
# For development convenience, configure the ToS/Privacy Policies