Refactor models.completely_open to take a Realm instead of a domain.

This commit is contained in:
Rishi Gupta 2016-12-23 17:10:26 -08:00 committed by Tim Abbott
parent cd7d8bfbea
commit a87e653c32
4 changed files with 10 additions and 10 deletions

View File

@ -14,7 +14,7 @@ from zerver.lib.actions import do_change_password, is_inactive, user_email_is_un
from zerver.lib.name_restrictions import is_reserved_subdomain, is_disposable_domain
from zerver.lib.utils import get_subdomain, check_subdomain
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
completely_open, get_realm, get_realm_by_email_domain, get_realm_by_string_id, \
get_realm, get_realm_by_email_domain, get_realm_by_string_id, \
get_unique_open_realm, email_to_domain, email_allowed_for_realm
from zproject.backends import password_auth_enabled

View File

@ -261,12 +261,11 @@ def get_realm_by_string_id(string_id):
except Realm.DoesNotExist:
return None
def completely_open(domain):
# type: (Text) -> bool
# This domain is completely open to everyone on the internet to
# join. E-mail addresses do not need to match the domain and
def completely_open(realm):
# type: (Realm) -> bool
# This realm is completely open to everyone on the internet to
# join. E-mail addresses do not need to match a realmalias and
# an invite from an existing user is not required.
realm = get_realm(domain)
if not realm:
return False
return not realm.invite_required and not realm.restricted_to_domain

View File

@ -2282,7 +2282,7 @@ class TestOpenRealms(ZulipTestCase):
self.assertEqual(get_unique_open_realm(), None)
mit_realm.restricted_to_domain = False
mit_realm.save()
self.assertTrue(completely_open(mit_realm.domain))
self.assertTrue(completely_open(mit_realm))
self.assertEqual(get_unique_open_realm(), None)
with self.settings(SYSTEM_ONLY_REALMS={"zulip.com"}):
self.assertEqual(get_unique_open_realm(), mit_realm)

View File

@ -316,21 +316,22 @@ def create_homepage_form(request, user_info=None):
def create_preregistration_user(email, request, realm_creation=False):
# type: (Text, HttpRequest, bool) -> HttpResponse
domain = request.session.get("domain")
if completely_open(domain):
realm = get_realm(domain)
if completely_open(realm):
# Clear the "domain" from the session object; it's no longer needed
request.session["domain"] = None
# The user is trying to sign up for a completely open realm,
# so create them a PreregistrationUser for that realm
return PreregistrationUser.objects.create(email=email,
realm=get_realm(domain),
realm=realm,
realm_creation=realm_creation)
return PreregistrationUser.objects.create(email=email, realm_creation=realm_creation)
def accounts_home_with_domain(request, domain):
# type: (HttpRequest, str) -> HttpResponse
if not settings.REALMS_HAVE_SUBDOMAINS and completely_open(domain):
if not settings.REALMS_HAVE_SUBDOMAINS and completely_open(get_realm(domain)):
# You can sign up for a completely open realm through a
# special registration path that contains the domain in the
# URL. We store this information in the session rather than