From 0884588a5e2ba073c65f3e9e9ab3bf1bdb5f37d6 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 18 Oct 2017 22:46:05 -0700 Subject: [PATCH] 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. --- zerver/lib/subdomains.py | 6 ++++-- zerver/models.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/lib/subdomains.py b/zerver/lib/subdomains.py index 20cb651af0..4727756caa 100644 --- a/zerver/lib/subdomains.py +++ b/zerver/lib/subdomains.py @@ -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): diff --git a/zerver/models.py b/zerver/models.py index 57db99751a..3a41ad3107 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -137,6 +137,7 @@ class Realm(ModelReprMixin, models.Model): MAX_REALM_NAME_LENGTH = 40 MAX_REALM_SUBDOMAIN_LENGTH = 40 AUTHENTICATION_FLAGS = [u'Google', u'Email', u'GitHub', u'LDAP', u'Dev', u'RemoteUser'] + SUBDOMAIN_FOR_ROOT_DOMAIN = '' name = models.CharField(max_length=MAX_REALM_NAME_LENGTH, null=True) # type: Optional[Text] string_id = models.CharField(max_length=MAX_REALM_SUBDOMAIN_LENGTH, unique=True) # type: Text