mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	subdomains: Fix some implicit uses of "" for the root subdomain.
These are just instances that jumped out at me while working on the subdomains code, mostly while grepping for get_subdomain call sites. I haven't attempted a comprehensive search, and there are likely still others left.
This commit is contained in:
		@@ -72,7 +72,8 @@ def zulip_default_context(request):
 | 
			
		||||
    about_link_disabled = settings.ABOUT_LINK_DISABLED
 | 
			
		||||
    find_team_link_disabled = settings.FIND_TEAM_LINK_DISABLED
 | 
			
		||||
 | 
			
		||||
    if settings.ROOT_DOMAIN_LANDING_PAGE and get_subdomain(request) == "":
 | 
			
		||||
    if (settings.ROOT_DOMAIN_LANDING_PAGE
 | 
			
		||||
            and get_subdomain(request) == Realm.SUBDOMAIN_FOR_ROOT_DOMAIN):
 | 
			
		||||
        register_link_disabled = True
 | 
			
		||||
        login_link_disabled = True
 | 
			
		||||
        about_link_disabled = True
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,8 @@ def get_subdomain(request):
 | 
			
		||||
def is_subdomain_root_or_alias(request):
 | 
			
		||||
    # type: (HttpRequest) -> bool
 | 
			
		||||
    subdomain = _extract_subdomain(request)
 | 
			
		||||
    return not subdomain or subdomain in settings.ROOT_SUBDOMAIN_ALIASES
 | 
			
		||||
    return (subdomain == Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
 | 
			
		||||
            or subdomain in settings.ROOT_SUBDOMAIN_ALIASES)
 | 
			
		||||
 | 
			
		||||
def user_matches_subdomain(realm_subdomain, user_profile):
 | 
			
		||||
    # type: (Optional[Text], UserProfile) -> bool
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ from zerver.lib.utils import statsd
 | 
			
		||||
from zerver.lib.queue import queue_json_publish
 | 
			
		||||
from zerver.lib.cache import get_remote_cache_time, get_remote_cache_requests
 | 
			
		||||
from zerver.lib.bugdown import get_bugdown_time, get_bugdown_requests
 | 
			
		||||
from zerver.models import flush_per_request_caches, get_realm
 | 
			
		||||
from zerver.models import Realm, flush_per_request_caches, get_realm
 | 
			
		||||
from zerver.lib.exceptions import RateLimited
 | 
			
		||||
from django.contrib.sessions.middleware import SessionMiddleware
 | 
			
		||||
from django.views.csrf import csrf_failure as html_csrf_failure
 | 
			
		||||
@@ -378,7 +378,7 @@ class SessionHostDomainMiddleware(SessionMiddleware):
 | 
			
		||||
        if (not request.path.startswith("/static/") and not request.path.startswith("/api/") and
 | 
			
		||||
                not request.path.startswith("/json/")):
 | 
			
		||||
            subdomain = get_subdomain(request)
 | 
			
		||||
            if subdomain != "":
 | 
			
		||||
            if subdomain != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
 | 
			
		||||
                realm = get_realm(subdomain)
 | 
			
		||||
                if (realm is None):
 | 
			
		||||
                    return render(request, "zerver/invalid_realm.html")
 | 
			
		||||
 
 | 
			
		||||
@@ -660,7 +660,7 @@ def get_auth_backends_data(request):
 | 
			
		||||
        realm = Realm.objects.get(string_id=subdomain)
 | 
			
		||||
    except Realm.DoesNotExist:
 | 
			
		||||
        # If not the root subdomain, this is an error
 | 
			
		||||
        if subdomain != "":
 | 
			
		||||
        if subdomain != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
 | 
			
		||||
            raise JsonableError(_("Invalid subdomain"))
 | 
			
		||||
        # With the root subdomain, it's an error or not depending
 | 
			
		||||
        # whether ROOT_DOMAIN_LANDING_PAGE (which indicates whether
 | 
			
		||||
 
 | 
			
		||||
@@ -79,7 +79,7 @@ def home(request):
 | 
			
		||||
    # page, not the login form, on the root domain
 | 
			
		||||
 | 
			
		||||
    subdomain = get_subdomain(request)
 | 
			
		||||
    if subdomain != "":
 | 
			
		||||
    if subdomain != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
 | 
			
		||||
        return home_real(request)
 | 
			
		||||
 | 
			
		||||
    return render(request, 'zerver/hello.html')
 | 
			
		||||
 
 | 
			
		||||
@@ -13,18 +13,20 @@ from zerver.decorator import has_request_variables, REQ
 | 
			
		||||
from zerver.lib import bugdown
 | 
			
		||||
from zerver.lib.integrations import CATEGORIES, INTEGRATIONS, HUBOT_LOZENGES
 | 
			
		||||
from zerver.lib.subdomains import get_subdomain
 | 
			
		||||
from zerver.models import Realm
 | 
			
		||||
from zerver.templatetags.app_filters import render_markdown_path
 | 
			
		||||
 | 
			
		||||
def add_api_uri_context(context, request):
 | 
			
		||||
    # type: (Dict[str, Any], HttpRequest) -> None
 | 
			
		||||
    subdomain = get_subdomain(request)
 | 
			
		||||
    if subdomain or not settings.ROOT_DOMAIN_LANDING_PAGE:
 | 
			
		||||
    if (subdomain != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
 | 
			
		||||
            or not settings.ROOT_DOMAIN_LANDING_PAGE):
 | 
			
		||||
        display_subdomain = subdomain
 | 
			
		||||
        html_settings_links = True
 | 
			
		||||
    else:
 | 
			
		||||
        display_subdomain = 'yourZulipDomain'
 | 
			
		||||
        html_settings_links = False
 | 
			
		||||
    if display_subdomain != "":
 | 
			
		||||
    if display_subdomain != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
 | 
			
		||||
        external_api_path_subdomain = '%s.%s' % (display_subdomain,
 | 
			
		||||
                                                 settings.EXTERNAL_API_PATH)
 | 
			
		||||
    else:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user