Remove special flow for open realm sign-up when realms have subdomains.

Redirects /register/<domain> to /accounts/register when
REALMS_HAVE_SUBDOMAINS.
This commit is contained in:
Rishi Gupta 2016-11-07 21:17:44 -08:00 committed by Tim Abbott
parent b114690bd5
commit 1e6ae537bd
4 changed files with 8 additions and 79 deletions

View File

@ -1,10 +0,0 @@
{% extends "zerver/portico.html" %}
{% block portico_content %}
<h3>{{ _('Register through proper link') }}</h3>
<p>{{ _('Hi there! Thank you for your interest in Zulip.') }}</p>
<p>{% trans %}Please register using <a href='{{ link }}'>this link</a>.{% endtrans %}</p>
{% endblock %}

View File

@ -626,7 +626,10 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
def test_google_oauth2_registration(self):
# type: () -> None
"""If the user doesn't exist yet, Google auth can be used to register an account"""
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
with self.settings(REALMS_HAVE_SUBDOMAINS=True), \
mock.patch('zerver.views.auth.get_subdomain', return_value='zulip'), \
mock.patch('zerver.views.get_subdomain', return_value='zulip'):
email = "newuser@zulip.com"
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
@ -645,10 +648,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
parsed_url.path)
self.assertEquals(uri, 'http://zulip.testserver/accounts/login/subdomain/')
with mock.patch('zerver.views.auth.get_subdomain', return_value='zulip'), \
mock.patch('zerver.views.get_subdomain', return_value='zulip'):
result = self.client_get(result.url)
result = self.client_get(result.url)
result = self.client_get(result.url) # Call the confirmation url.
key_match = re.search('value="(?P<key>[0-9a-f]+)" name="key"', result.content.decode("utf-8"))
name_match = re.search('value="(?P<name>[^"]+)" name="full_name"', result.content.decode("utf-8"))

View File

@ -764,53 +764,6 @@ class UserSignUpTest(ZulipTestCase):
from django.core.mail import outbox
outbox.pop()
def test_completely_open_domain_under_subdomains(self):
# type: () -> None
username = "user1"
password = "test"
domain = "zulip.com"
email = "user1@acme.com"
subdomain = "zulip"
realm_name = "Zulip"
realm = get_realm(domain)
realm.restricted_to_domain = False
realm.invite_required = False
realm.save()
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
with patch('zerver.views.get_subdomain', return_value=subdomain):
result = self.client_post('/register/', {'email': email})
self.assertEquals(result.status_code, 302)
self.assertTrue(result["Location"].endswith(
"/accounts/send_confirm/%s" % (email,)))
result = self.client_get(result["Location"])
self.assert_in_response("Check your email so we can get started.", result)
# Visit the confirmation link.
from django.core.mail import outbox
for message in reversed(outbox):
if email in message.to:
confirmation_link_pattern = re.compile(settings.EXTERNAL_HOST + "(\S+)>")
confirmation_url = confirmation_link_pattern.search(
message.body).groups()[0]
break
else:
raise ValueError("Couldn't find a confirmation email.")
result = self.client_get(confirmation_url)
self.assertEquals(result.status_code, 200)
result = self.submit_reg_form_for_user(username,
password,
domain='acme.com',
realm_name=realm_name,
realm_subdomain=subdomain,
# Pass HTTP_HOST for the target subdomain
HTTP_HOST=subdomain + ".testserver")
self.assertEquals(result.status_code, 200)
self.assertIn('Register through proper link', result.content.decode('utf8'))
def test_unique_completely_open_domain(self):
# type: () -> None
username = "user1"

View File

@ -123,22 +123,8 @@ def accounts_register(request):
realm = None
domain = None
elif settings.REALMS_HAVE_SUBDOMAINS:
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):
# When subdomains are enabled and the user is registering into a
# completely open subdomain without going through the correct url
# for the completely open domains.
# NOTE: When the user comes through the correct url then
# `prereg_user.realm` will have the correct value and this branch
# will not run.
path = reverse('zerver.views.accounts_home_with_domain',
kwargs={'domain': subdomain_realm.domain})
ctx = {"link": "%s%s" % (subdomain_realm.uri, path)}
return render_to_response("zerver/completely_open_link.html", ctx)
else:
realm = get_realm(domain)
realm = get_realm_by_string_id(get_subdomain(request))
domain = realm.domain
else:
domain = resolve_email_to_domain(email)
realm = get_realm(domain)
@ -350,7 +336,7 @@ def create_preregistration_user(email, request, realm_creation=False):
def accounts_home_with_domain(request, domain):
# type: (HttpRequest, str) -> HttpResponse
if completely_open(domain):
if not settings.REALMS_HAVE_SUBDOMAINS and completely_open(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