mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
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:
@@ -4092,16 +4092,7 @@ def email_not_system_bot(email: Text) -> None:
|
|||||||
raise ValidationError('%s is an email address reserved for system bots' % (email,))
|
raise ValidationError('%s is an email address reserved for system bots' % (email,))
|
||||||
|
|
||||||
def validate_email_for_realm(target_realm: Realm, email: Text) -> None:
|
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)
|
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
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing_user_profile = get_user(email, target_realm)
|
existing_user_profile = get_user(email, target_realm)
|
||||||
|
|||||||
@@ -266,6 +266,10 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||||||
user2 = self.create_user(user2_email)
|
user2 = self.create_user(user2_email)
|
||||||
self.create_user(user3_email)
|
self.create_user(user3_email)
|
||||||
feedback_bot = get_system_bot(feedback_email)
|
feedback_bot = get_system_bot(feedback_email)
|
||||||
|
with self.settings(CROSS_REALM_BOT_EMAILS=['feedback@zulip.com', 'welcome-bot@zulip.com']):
|
||||||
|
# HACK: We should probably be creating this "bot" user another
|
||||||
|
# way, but since you can't register a user with a
|
||||||
|
# cross-realm email, we need to hide this for now.
|
||||||
support_bot = self.create_user(support_email)
|
support_bot = self.create_user(support_email)
|
||||||
|
|
||||||
# Users can PM themselves
|
# Users can PM themselves
|
||||||
|
|||||||
Reference in New Issue
Block a user