context_processors.py: Add flag for whether user is logged in.

This commit is contained in:
Jack Zhang 2017-08-03 18:59:52 -07:00 committed by Tim Abbott
parent 182570d5f3
commit a533ab5881
2 changed files with 8 additions and 2 deletions

View File

@ -85,6 +85,10 @@ def zulip_default_context(request):
if settings.ZILENCER_ENABLED:
apps_page_url = '/apps/'
user_is_authenticated = False
if hasattr(request, 'user') and hasattr(request.user, 'is_authenticated'):
user_is_authenticated = request.user.is_authenticated.value
return {
'realms_have_subdomains': settings.REALMS_HAVE_SUBDOMAINS,
'custom_logo_url': settings.CUSTOM_LOGO_URL,
@ -121,6 +125,7 @@ def zulip_default_context(request):
'password_min_length': settings.PASSWORD_MIN_LENGTH,
'password_min_quality': settings.PASSWORD_MIN_ZXCVBN_QUALITY,
'zulip_version': ZULIP_VERSION,
'user_is_authenticated': user_is_authenticated,
}

View File

@ -277,13 +277,14 @@ class HostRequestMock(object):
"""A mock request object where get_host() works. Useful for testing
routes that use Zulip's subdomains feature"""
def __init__(self, host=settings.EXTERNAL_HOST):
# type: (Text) -> None
def __init__(self, user_profile=None, host=settings.EXTERNAL_HOST):
# type: (UserProfile, Text) -> None
self.host = host
self.GET = {} # type: Dict[str, Any]
self.POST = {} # type: Dict[str, Any]
self.META = {'PATH_INFO': 'test'}
self.path = ''
self.user = user_profile
def get_host(self):
# type: () -> Text