auth: Remove unnecessary case from validate_email_for_realm.

The removed code path was only needed due to buggy setup code in the
test_cross_realm_scenarios test.  We address that with a less buggy
workaround, and which lets us remove unnecessary complexity from this
important validation function.

Thanks for Umair Waheed for some preliminary work on this.

Fixes #7561.
This commit is contained in:
Tim Abbott
2018-04-28 10:59:39 -07:00
parent 16873cd1ff
commit 127ac0df54
2 changed files with 6 additions and 11 deletions

View File

@@ -4092,16 +4092,7 @@ def email_not_system_bot(email: Text) -> None:
raise ValidationError('%s is an email address reserved for system bots' % (email,))
def validate_email_for_realm(target_realm: Realm, email: Text) -> None:
try:
# Registering with a system bot's email is not allowed...
email_not_system_bot(email)
except ValidationError:
# ... unless this is the first user with that email. This
# should be impossible in production, because these users are
# created by initialize_voyager_db, but it happens in a test's
# setup. (This would be a good wrinkle to clean up.)
if UserProfile.objects.filter(email__iexact=email).exists():
raise
email_not_system_bot(email)
try:
existing_user_profile = get_user(email, target_realm)