diff --git a/zerver/forms.py b/zerver/forms.py index a07637fa98..aeded481f0 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -10,7 +10,7 @@ from django.db.models.query import QuerySet from jinja2 import Markup as mark_safe from django.core.urlresolvers import reverse 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 import logging @@ -97,7 +97,7 @@ class RegistrationForm(forms.Form): def clean_realm_subdomain(self): # type: () -> str data = self.cleaned_data['realm_subdomain'] - realm = resolve_subdomain_to_realm(data) + realm = get_realm_by_string_id(data) if realm is not None: raise ValidationError(subdomain_unavailable(data)) return data @@ -135,7 +135,7 @@ class HomepageForm(forms.Form): return data # 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 completely_open(subdomain_realm.domain)): return data diff --git a/zerver/middleware.py b/zerver/middleware.py index d8de1d7b76..d32871bb12 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -14,7 +14,7 @@ from zerver.lib.utils import statsd, get_subdomain 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, resolve_subdomain_to_realm +from zerver.models import flush_per_request_caches, get_realm_by_string_id from zerver.exceptions import RateLimited from django.contrib.sessions.middleware import SessionMiddleware 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, settings.EXTERNAL_HOST)) if subdomain != "": - realm = resolve_subdomain_to_realm(subdomain) + realm = get_realm_by_string_id(subdomain) if (realm is None): return render_to_response("zerver/invalid_realm.html") """ diff --git a/zerver/models.py b/zerver/models.py index b311eac7c8..f67f313bcb 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -284,13 +284,6 @@ def resolve_email_to_domain(email): domain = alias.realm.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? # (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, diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index bf227d6a7b..209cf6e701 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -22,7 +22,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \ get_stream, UserPresence, get_recipient, name_changes_disabled, \ split_email_to_domain, resolve_email_to_domain, email_to_username, get_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, \ do_activate_user, do_create_user, do_create_realm, set_default_streams, \ update_user_presence, do_events_register, \ @@ -123,7 +123,7 @@ def accounts_register(request): realm = None domain = None 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 = subdomain_realm.domain if subdomain_realm else domain if completely_open(domain):