registration: Move "already in realm" check outside of validation.

Checking for `validate_email_not_already_in_realm` again (after the
form already did so), but only in the case that the form fails to
validate, means that we may be spending time pushing totally invalid
emails to the DB to check.  In the case of emails containing nulls,
this can even trigger a 500 error from PostgreSQL.

Stop calling `validate_email_not_already_in_realm` in the form
validation. The form is currently only used in two places -- in
`accounts_home` and in `maybe_send_to_registration`.  The latter is
only called if the address is known to not currently have an account,
so checking in there is unnecessary; and in the former case, we wish
different behaviour (the redirect) than just validation failure, which
is all the validator can do.

Fixes #17015.

Co-authored-by: Alex Vandiver <alexmv@zulip.com>
This commit is contained in:
Tushar912
2021-01-06 23:11:44 +05:30
committed by Alex Vandiver
parent 410bb8ad89
commit c60f48c889
3 changed files with 19 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ from two_factor.forms import AuthenticationTokenForm as TwoFactorAuthenticationT
from two_factor.utils import totp_digits
from zerver.lib.actions import do_change_password, email_not_system_bot
from zerver.lib.email_validation import email_allowed_for_realm, validate_email_not_already_in_realm
from zerver.lib.email_validation import email_allowed_for_realm
from zerver.lib.name_restrictions import is_disposable_domain, is_reserved_subdomain
from zerver.lib.rate_limiter import RateLimited, RateLimitedObject
from zerver.lib.request import JsonableError
@@ -177,8 +177,6 @@ class HomepageForm(forms.Form):
except EmailContainsPlusError:
raise ValidationError(_("Email addresses containing + are not allowed in this organization."))
validate_email_not_already_in_realm(realm, email)
if realm.is_zephyr_mirror_realm:
email_is_not_mit_mailing_list(email)