[manual] Allow signups for emails held by non-MIT mirror dummy accounts.

Before this is deployed to prod, we need to manually frob our database
to set the is_mirror_dummy=True bit for all existing mirror users.

(imported from commit 39f1938cef091cf1d7d97307f76b137fe1d92b6c)
This commit is contained in:
Tim Abbott
2014-01-07 13:13:45 -05:00
committed by Waseem Daher
parent 75d1366ae1
commit 4bf3ace444
3 changed files with 26 additions and 13 deletions

View File

@@ -8,17 +8,10 @@ from django.conf import settings
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
completely_open, resolve_email_to_domain, get_realm
from zerver.lib.actions import do_change_password
from zerver.lib.actions import do_change_password, is_inactive
from zproject.backends import password_auth_enabled
import DNS
def is_inactive(value):
try:
if get_user_profile_by_email(value).is_active:
raise ValidationError(u'%s is already active' % value)
except UserProfile.DoesNotExist:
pass
SIGNUP_STRING = '<a href="https://zulip.com/signup">Sign up</a> to find out when Zulip is ready for you.'
def has_valid_realm(value):

View File

@@ -2210,6 +2210,13 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
if messages:
do_send_missedmessage_events(user_profile, messages)
def is_inactive(value):
try:
if get_user_profile_by_email(value).is_active:
raise ValidationError(u'%s is already active' % value)
except UserProfile.DoesNotExist:
pass
def user_email_is_unique(value):
try:
get_user_profile_by_email(value)
@@ -2240,7 +2247,16 @@ def do_invite_users(user_profile, invitee_emails, streams):
continue
try:
user_email_is_unique(email)
existing_user_profile = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
existing_user_profile = None
try:
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
# Mirror dummy users to be activated must be inactive
is_inactive(email)
else:
# Other users should not already exist at all.
user_email_is_unique(email)
except ValidationError:
skipped.append((email, "Already has an account."))
continue

View File

@@ -218,6 +218,10 @@ def accounts_register(request):
prereg_user = confirmation.content_object
email = prereg_user.email
mit_beta_user = isinstance(confirmation.content_object, MitUser)
try:
existing_user_profile = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
existing_user_profile = None
validators.validate_email(email)
# If someone invited you, you are joining their realm regardless
@@ -242,8 +246,8 @@ def accounts_register(request):
{"deactivated_domain_name": realm.name})
try:
if mit_beta_user:
# MIT users already exist, but are supposed to be inactive.
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
# Mirror dummy users to be activated must be inactive
is_inactive(email)
else:
# Other users should not already exist at all.
@@ -313,9 +317,9 @@ def accounts_register(request):
first_in_realm = len(UserProfile.objects.filter(realm=realm, is_bot=False)) == 0
# FIXME: sanitize email addresses and fullname
if mit_beta_user:
if existing_user_profile is not None and existing_user_profile.is_mirror_dummy:
try:
user_profile = get_user_profile_by_email(email)
user_profile = existing_user_profile
do_activate_user(user_profile)
do_change_password(user_profile, password)
do_change_full_name(user_profile, full_name)