Remove old MitUser model and related code.

The MitUser model caused a constant series of little problems for
users with mit.edu email addresses trying to sign up for different
Zulip servers.

The new implementation just uses conditionals on the realm object when
selecting the confirmation template to use.
This commit is contained in:
Tim Abbott 2016-07-26 17:56:36 -07:00
parent ed6c134cf4
commit df525ad1c5
4 changed files with 26 additions and 19 deletions

View File

@ -90,8 +90,12 @@ class ConfirmationManager(models.Manager):
}) })
if additional_context is not None: if additional_context is not None:
context.update(additional_context) context.update(additional_context)
if obj.realm is not None and obj.realm.is_zephyr_mirror_realm:
template_name = "mituser"
else:
template_name = obj._meta.model_name
templates = [ templates = [
'confirmation/%s_confirmation_email_subject.txt' % obj._meta.model_name, 'confirmation/%s_confirmation_email_subject.txt' % (template_name,),
'confirmation/confirmation_email_subject.txt', 'confirmation/confirmation_email_subject.txt',
] ]
if subject_template_path: if subject_template_path:
@ -100,7 +104,7 @@ class ConfirmationManager(models.Manager):
template = loader.select_template(templates) template = loader.select_template(templates)
subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please
templates = [ templates = [
'confirmation/%s_confirmation_email_body.txt' % obj._meta.model_name, 'confirmation/%s_confirmation_email_body.txt' % (template_name,),
'confirmation/confirmation_email_body.txt', 'confirmation/confirmation_email_body.txt',
] ]
if body_template_path: if body_template_path:

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('zerver', '0025_realm_message_content_edit_limit'),
]
operations = [
migrations.DeleteModel(
name='MitUser',
),
]

View File

@ -555,12 +555,6 @@ class PushDeviceToken(models.Model):
# [optional] Contains the app id of the device if it is an iOS device # [optional] Contains the app id of the device if it is an iOS device
ios_app_id = models.TextField(null=True) # type: Optional[text_type] ios_app_id = models.TextField(null=True) # type: Optional[text_type]
class MitUser(models.Model):
email = models.EmailField(unique=True) # type: text_type
# status: whether an object has been confirmed.
# if confirmed, set to confirmation.settings.STATUS_ACTIVE
status = models.IntegerField(default=0) # type: int
def generate_email_token_for_stream(): def generate_email_token_for_stream():
# type: () -> text_type # type: () -> text_type
return generate_random_token(32) return generate_random_token(32)

View File

@ -22,7 +22,7 @@ from django.middleware.csrf import get_token
from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
Recipient, Realm, UserMessage, DefaultStream, RealmEmoji, RealmAlias, \ Recipient, Realm, UserMessage, DefaultStream, RealmEmoji, RealmAlias, \
RealmFilter, \ RealmFilter, \
PreregistrationUser, get_client, MitUser, UserActivity, \ PreregistrationUser, get_client, UserActivity, \
get_stream, UserPresence, get_recipient, \ get_stream, UserPresence, get_recipient, \
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, remote_user_to_email, email_allowed_for_realm, \ completely_open, get_unique_open_realm, remote_user_to_email, email_allowed_for_realm, \
@ -89,7 +89,6 @@ def accounts_register(request):
prereg_user = confirmation.content_object prereg_user = confirmation.content_object
email = prereg_user.email email = prereg_user.email
realm_creation = prereg_user.realm_creation realm_creation = prereg_user.realm_creation
mit_beta_user = isinstance(confirmation.content_object, MitUser)
try: try:
existing_user_profile = get_user_profile_by_email(email) existing_user_profile = get_user_profile_by_email(email)
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
@ -102,16 +101,14 @@ def accounts_register(request):
if unique_open_realm is not None: if unique_open_realm is not None:
realm = unique_open_realm realm = unique_open_realm
domain = realm.domain domain = realm.domain
elif not mit_beta_user and prereg_user.referred_by: elif prereg_user.referred_by:
# If someone invited you, you are joining their realm regardless # If someone invited you, you are joining their realm regardless
# of your e-mail address. # of your e-mail address.
#
# MitUsers can't be referred and don't have a referred_by field.
realm = prereg_user.referred_by.realm realm = prereg_user.referred_by.realm
domain = realm.domain domain = realm.domain
if not email_allowed_for_realm(email, realm): if not email_allowed_for_realm(email, realm):
return render_to_response("zerver/closed_realm.html", {"closed_domain_name": realm.name}) return render_to_response("zerver/closed_realm.html", {"closed_domain_name": realm.name})
elif not mit_beta_user and prereg_user.realm: elif prereg_user.realm:
# You have a realm set, even though nobody referred you. This # You have a realm set, even though nobody referred you. This
# happens if you sign up through a special URL for an open # happens if you sign up through a special URL for an open
# realm. # realm.
@ -694,11 +691,6 @@ def create_preregistration_user(email, request, realm_creation=False):
realm=get_realm(domain), realm=get_realm(domain),
realm_creation=realm_creation) realm_creation=realm_creation)
# MIT users who are not explicitly signing up for an open realm
# require special handling (They may already have an (inactive)
# account, for example)
if split_email_to_domain(email) == "mit.edu":
return MitUser.objects.get_or_create(email=email)[0]
return PreregistrationUser.objects.create(email=email, realm_creation=realm_creation) return PreregistrationUser.objects.create(email=email, realm_creation=realm_creation)
def accounts_home_with_domain(request, domain): def accounts_home_with_domain(request, domain):