subdomains: Add a variable for how root domain is represented.

We use Realm.SUBDOMAIN_FOR_ROOT_DOMAIN as the special name for how the
root domain is referred to as a subdomain in the code.
This commit is contained in:
Tim Abbott
2017-10-18 22:46:05 -07:00
parent 07438b2f2c
commit 0884588a5e
2 changed files with 5 additions and 2 deletions

View File

@@ -4,19 +4,21 @@ from django.conf import settings
from django.http import HttpRequest
from typing import Optional, Text
from zerver.models import get_realm, Realm
def _extract_subdomain(request):
# type: (HttpRequest) -> Text
domain = request.get_host().lower()
index = domain.find("." + settings.EXTERNAL_HOST)
if index == -1:
return ""
return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
return domain[0:index]
def get_subdomain(request):
# type: (HttpRequest) -> Text
subdomain = _extract_subdomain(request)
if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:
return ""
return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
return subdomain
def is_subdomain_root_or_alias(request):