mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	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:
		@@ -4,19 +4,21 @@ from django.conf import settings
 | 
				
			|||||||
from django.http import HttpRequest
 | 
					from django.http import HttpRequest
 | 
				
			||||||
from typing import Optional, Text
 | 
					from typing import Optional, Text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from zerver.models import get_realm, Realm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _extract_subdomain(request):
 | 
					def _extract_subdomain(request):
 | 
				
			||||||
    # type: (HttpRequest) -> Text
 | 
					    # type: (HttpRequest) -> Text
 | 
				
			||||||
    domain = request.get_host().lower()
 | 
					    domain = request.get_host().lower()
 | 
				
			||||||
    index = domain.find("." + settings.EXTERNAL_HOST)
 | 
					    index = domain.find("." + settings.EXTERNAL_HOST)
 | 
				
			||||||
    if index == -1:
 | 
					    if index == -1:
 | 
				
			||||||
        return ""
 | 
					        return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
 | 
				
			||||||
    return domain[0:index]
 | 
					    return domain[0:index]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_subdomain(request):
 | 
					def get_subdomain(request):
 | 
				
			||||||
    # type: (HttpRequest) -> Text
 | 
					    # type: (HttpRequest) -> Text
 | 
				
			||||||
    subdomain = _extract_subdomain(request)
 | 
					    subdomain = _extract_subdomain(request)
 | 
				
			||||||
    if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:
 | 
					    if subdomain in settings.ROOT_SUBDOMAIN_ALIASES:
 | 
				
			||||||
        return ""
 | 
					        return Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
 | 
				
			||||||
    return subdomain
 | 
					    return subdomain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def is_subdomain_root_or_alias(request):
 | 
					def is_subdomain_root_or_alias(request):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -137,6 +137,7 @@ class Realm(ModelReprMixin, models.Model):
 | 
				
			|||||||
    MAX_REALM_NAME_LENGTH = 40
 | 
					    MAX_REALM_NAME_LENGTH = 40
 | 
				
			||||||
    MAX_REALM_SUBDOMAIN_LENGTH = 40
 | 
					    MAX_REALM_SUBDOMAIN_LENGTH = 40
 | 
				
			||||||
    AUTHENTICATION_FLAGS = [u'Google', u'Email', u'GitHub', u'LDAP', u'Dev', u'RemoteUser']
 | 
					    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]
 | 
					    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
 | 
					    string_id = models.CharField(max_length=MAX_REALM_SUBDOMAIN_LENGTH, unique=True)  # type: Text
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user