mirror of https://github.com/zulip/zulip.git
settings: Fix 500 when trying to change email to disposable email.
Fixes #9240
This commit is contained in:
parent
76fba19d20
commit
733da0ac07
|
@ -83,7 +83,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
||||||
get_display_recipient_by_id, query_for_ids, get_huddle_recipient, \
|
get_display_recipient_by_id, query_for_ids, get_huddle_recipient, \
|
||||||
UserGroup, UserGroupMembership, get_default_stream_groups, \
|
UserGroup, UserGroupMembership, get_default_stream_groups, \
|
||||||
get_bot_services, get_bot_dicts_in_realm, DomainNotAllowedForRealmError, \
|
get_bot_services, get_bot_dicts_in_realm, DomainNotAllowedForRealmError, \
|
||||||
get_services_for_bots
|
get_services_for_bots, DisposableEmailError
|
||||||
|
|
||||||
from zerver.lib.alert_words import alert_words_in_realm
|
from zerver.lib.alert_words import alert_words_in_realm
|
||||||
from zerver.lib.avatar import avatar_url, avatar_url_from_dict
|
from zerver.lib.avatar import avatar_url, avatar_url_from_dict
|
||||||
|
@ -4158,6 +4158,8 @@ def validate_email(user_profile: UserProfile, email: Text) -> Tuple[Optional[str
|
||||||
email_allowed_for_realm(email, user_profile.realm)
|
email_allowed_for_realm(email, user_profile.realm)
|
||||||
except DomainNotAllowedForRealmError:
|
except DomainNotAllowedForRealmError:
|
||||||
return _("Outside your domain."), None
|
return _("Outside your domain."), None
|
||||||
|
except DisposableEmailError:
|
||||||
|
return _("Please use your real email address."), None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_email_for_realm(user_profile.realm, email)
|
validate_email_for_realm(user_profile.realm, email)
|
||||||
|
|
|
@ -113,6 +113,18 @@ class ChangeSettingsTest(ZulipTestCase):
|
||||||
dict(full_name='Opheli*'))
|
dict(full_name='Opheli*'))
|
||||||
self.assert_json_error(json_result, 'Invalid characters in name!')
|
self.assert_json_error(json_result, 'Invalid characters in name!')
|
||||||
|
|
||||||
|
def test_change_email_to_disposable_email(self) -> None:
|
||||||
|
email = self.example_email("hamlet")
|
||||||
|
self.login(email)
|
||||||
|
realm = get_realm("zulip")
|
||||||
|
realm.disallow_disposable_email_addresses = True
|
||||||
|
realm.restricted_to_domain = False
|
||||||
|
realm.save()
|
||||||
|
|
||||||
|
json_result = self.client_patch("/json/settings",
|
||||||
|
dict(email='hamlet@mailnator.com'))
|
||||||
|
self.assert_json_error(json_result, 'Please use your real email address.')
|
||||||
|
|
||||||
# This is basically a don't-explode test.
|
# This is basically a don't-explode test.
|
||||||
def test_notify_settings(self) -> None:
|
def test_notify_settings(self) -> None:
|
||||||
for notification_setting in UserProfile.notification_setting_types:
|
for notification_setting in UserProfile.notification_setting_types:
|
||||||
|
|
|
@ -772,6 +772,23 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
||||||
self.invite(external_address, ["Denmark"]),
|
self.invite(external_address, ["Denmark"]),
|
||||||
"Some emails did not validate, so we didn't send any invitations.")
|
"Some emails did not validate, so we didn't send any invitations.")
|
||||||
|
|
||||||
|
def test_invite_using_disposable_email(self) -> None:
|
||||||
|
"""
|
||||||
|
In a realm with `restricted_to_domain = True`, you can't invite people
|
||||||
|
with a different domain from that of the realm or your e-mail address.
|
||||||
|
"""
|
||||||
|
zulip_realm = get_realm("zulip")
|
||||||
|
zulip_realm.restricted_to_domain = False
|
||||||
|
zulip_realm.disallow_disposable_email_addresses = True
|
||||||
|
zulip_realm.save()
|
||||||
|
|
||||||
|
self.login(self.example_email("hamlet"))
|
||||||
|
external_address = "foo@mailnator.com"
|
||||||
|
|
||||||
|
self.assert_json_error(
|
||||||
|
self.invite(external_address, ["Denmark"]),
|
||||||
|
"Some emails did not validate, so we didn't send any invitations.")
|
||||||
|
|
||||||
def test_invite_outside_domain_in_open_realm(self) -> None:
|
def test_invite_outside_domain_in_open_realm(self) -> None:
|
||||||
"""
|
"""
|
||||||
In a realm with `restricted_to_domain = False`, you can invite people
|
In a realm with `restricted_to_domain = False`, you can invite people
|
||||||
|
|
Loading…
Reference in New Issue