mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Add option for hosting each realm on its own subdomain.
This adds support for running a Zulip production server with each realm on its own unique subdomain, e.g. https://realm_name.example.com. This patch includes a ton of important features: * Configuring the Zulip sesion middleware to issue cookier correctly for the subdomains case. * Throwing an error if the user tries to visit an invalid subdomain. * Runs a portion of the Casper tests with REALMS_HAVE_SUBDOMAINS enabled to test the subdomain signup process. * Updating our integrations documentation to refer to the current subdomain. * Enforces that users can only login to the subdomain of their realm (but does not restrict the API; that will be tightened in a future commit). Note that toggling settings.REALMS_HAVE_SUBDOMAINS on a live server is not supported without manual intervention (the main problem will be adding "subdomain" values for all the existing realms). [substantially modified by tabbott as part of merging]
This commit is contained in:
@@ -13,6 +13,7 @@ import os
|
||||
from time import sleep
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest
|
||||
from six.moves import range
|
||||
from zerver.lib.str_utils import force_text
|
||||
|
||||
@@ -184,3 +185,21 @@ def query_chunker(queries, id_collector=None, chunk_size=1000, db_chunk_size=Non
|
||||
id_collector.update(tup_ids)
|
||||
|
||||
yield [row for row_id, i, row in tup_chunk]
|
||||
|
||||
def get_subdomain(request):
|
||||
# type: (HttpRequest) -> text_type
|
||||
domain = request.get_host().lower()
|
||||
index = domain.find("." + settings.EXTERNAL_HOST)
|
||||
if index == -1:
|
||||
return ""
|
||||
subdomain = domain[0:index]
|
||||
return subdomain
|
||||
|
||||
def check_subdomain(realm_subdomain, user_subdomain):
|
||||
# type: (text_type, text_type) -> bool
|
||||
if settings.REALMS_HAVE_SUBDOMAINS and realm_subdomain is not None:
|
||||
if (realm_subdomain == "" and user_subdomain is None):
|
||||
return True
|
||||
if realm_subdomain != user_subdomain:
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user