mirror of https://github.com/zulip/zulip.git
models.py: Replace resolve_subdomain_to_realm with get_realm_by_string_id.
No change in functionality.
This commit is contained in:
parent
655940acaf
commit
4a74301a62
|
@ -10,7 +10,7 @@ from django.db.models.query import QuerySet
|
||||||
from jinja2 import Markup as mark_safe
|
from jinja2 import Markup as mark_safe
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from zerver.models import resolve_subdomain_to_realm
|
from zerver.models import get_realm_by_string_id
|
||||||
from zerver.lib.utils import get_subdomain, check_subdomain
|
from zerver.lib.utils import get_subdomain, check_subdomain
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -97,7 +97,7 @@ class RegistrationForm(forms.Form):
|
||||||
def clean_realm_subdomain(self):
|
def clean_realm_subdomain(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
data = self.cleaned_data['realm_subdomain']
|
data = self.cleaned_data['realm_subdomain']
|
||||||
realm = resolve_subdomain_to_realm(data)
|
realm = get_realm_by_string_id(data)
|
||||||
if realm is not None:
|
if realm is not None:
|
||||||
raise ValidationError(subdomain_unavailable(data))
|
raise ValidationError(subdomain_unavailable(data))
|
||||||
return data
|
return data
|
||||||
|
@ -135,7 +135,7 @@ class HomepageForm(forms.Form):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# If the subdomain encodes a complete open realm, pass
|
# If the subdomain encodes a complete open realm, pass
|
||||||
subdomain_realm = resolve_subdomain_to_realm(self.subdomain)
|
subdomain_realm = get_realm_by_string_id(self.subdomain)
|
||||||
if (subdomain_realm is not None and
|
if (subdomain_realm is not None and
|
||||||
completely_open(subdomain_realm.domain)):
|
completely_open(subdomain_realm.domain)):
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -14,7 +14,7 @@ from zerver.lib.utils import statsd, get_subdomain
|
||||||
from zerver.lib.queue import queue_json_publish
|
from zerver.lib.queue import queue_json_publish
|
||||||
from zerver.lib.cache import get_remote_cache_time, get_remote_cache_requests
|
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.lib.bugdown import get_bugdown_time, get_bugdown_requests
|
||||||
from zerver.models import flush_per_request_caches, resolve_subdomain_to_realm
|
from zerver.models import flush_per_request_caches, get_realm_by_string_id
|
||||||
from zerver.exceptions import RateLimited
|
from zerver.exceptions import RateLimited
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
from django.views.csrf import csrf_failure as html_csrf_failure
|
from django.views.csrf import csrf_failure as html_csrf_failure
|
||||||
|
@ -356,7 +356,7 @@ class SessionHostDomainMiddleware(SessionMiddleware):
|
||||||
return redirect("%s%s" % (settings.EXTERNAL_URI_SCHEME,
|
return redirect("%s%s" % (settings.EXTERNAL_URI_SCHEME,
|
||||||
settings.EXTERNAL_HOST))
|
settings.EXTERNAL_HOST))
|
||||||
if subdomain != "":
|
if subdomain != "":
|
||||||
realm = resolve_subdomain_to_realm(subdomain)
|
realm = get_realm_by_string_id(subdomain)
|
||||||
if (realm is None):
|
if (realm is None):
|
||||||
return render_to_response("zerver/invalid_realm.html")
|
return render_to_response("zerver/invalid_realm.html")
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -284,13 +284,6 @@ def resolve_email_to_domain(email):
|
||||||
domain = alias.realm.domain
|
domain = alias.realm.domain
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
def resolve_subdomain_to_realm(subdomain):
|
|
||||||
# type: (text_type) -> Optional[Realm]
|
|
||||||
try:
|
|
||||||
return Realm.objects.get(string_id=subdomain)
|
|
||||||
except Realm.DoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Is a user with the given email address allowed to be in the given realm?
|
# Is a user with the given email address allowed to be in the given realm?
|
||||||
# (This function does not check whether the user has been invited to the realm.
|
# (This function does not check whether the user has been invited to the realm.
|
||||||
# So for invite-only realms, this is the test for whether a user can be invited,
|
# So for invite-only realms, this is the test for whether a user can be invited,
|
||||||
|
|
|
@ -22,7 +22,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
|
||||||
get_stream, UserPresence, get_recipient, name_changes_disabled, \
|
get_stream, UserPresence, get_recipient, name_changes_disabled, \
|
||||||
split_email_to_domain, resolve_email_to_domain, email_to_username, get_realm, \
|
split_email_to_domain, resolve_email_to_domain, email_to_username, get_realm, \
|
||||||
completely_open, get_unique_open_realm, email_allowed_for_realm, \
|
completely_open, get_unique_open_realm, email_allowed_for_realm, \
|
||||||
resolve_subdomain_to_realm, list_of_domains_for_realm
|
get_realm_by_string_id, list_of_domains_for_realm
|
||||||
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
|
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
|
||||||
do_activate_user, do_create_user, do_create_realm, set_default_streams, \
|
do_activate_user, do_create_user, do_create_realm, set_default_streams, \
|
||||||
update_user_presence, do_events_register, \
|
update_user_presence, do_events_register, \
|
||||||
|
@ -123,7 +123,7 @@ def accounts_register(request):
|
||||||
realm = None
|
realm = None
|
||||||
domain = None
|
domain = None
|
||||||
elif settings.REALMS_HAVE_SUBDOMAINS:
|
elif settings.REALMS_HAVE_SUBDOMAINS:
|
||||||
subdomain_realm = resolve_subdomain_to_realm(get_subdomain(request))
|
subdomain_realm = get_realm_by_string_id(get_subdomain(request))
|
||||||
domain = resolve_email_to_domain(email)
|
domain = resolve_email_to_domain(email)
|
||||||
domain = subdomain_realm.domain if subdomain_realm else domain
|
domain = subdomain_realm.domain if subdomain_realm else domain
|
||||||
if completely_open(domain):
|
if completely_open(domain):
|
||||||
|
|
Loading…
Reference in New Issue