Showing with 15 additions and 27 deletions.
  1. +0 −7 zerver/tests/test_email_change.py
  2. +2 −3 zerver/tests/test_signup.py
  3. +4 −4 zerver/views/email_log.py
  4. +1 −1 zerver/views/unsubscribe.py
  5. +8 −12 zerver/views/user_settings.py
@@ -37,13 +37,6 @@ def test_confirm_email_change_with_invalid_key(self):
response = self.client_get(url)
self.assert_in_success_response(["Whoops. The confirmation link is malformed."], response)

def test_email_change_when_not_logging_in(self):
# type: () -> None
key = generate_key()
url = confirmation_url(key, 'testserver', Confirmation.EMAIL_CHANGE)
response = self.client_get(url)
self.assertEqual(response.status_code, 302)

def test_confirm_email_change_when_time_exceeded(self):
# type: () -> None
user_profile = self.example_user('hamlet')
@@ -1107,10 +1107,9 @@ class EmailUnsubscribeTests(ZulipTestCase):
def test_error_unsubscribe(self):
# type: () -> None

# An invalid insubscribe token "test123" produces an error, in this
# case, a link malformed error.
# An invalid unsubscribe token "test123" produces an error.
result = self.client_get('/accounts/unsubscribe/missed_messages/test123')
self.assert_in_response('Make sure you copied the link', result)
self.assert_in_response('Unknown email unsubscribe request', result)

# An unknown message type "fake" produces an error.
user_profile = self.example_user('hamlet')
@@ -66,17 +66,17 @@ def generate_all_emails(request):
assert result.status_code == 200

# Verification for new email
result = client.patch('/json/settings', urllib.parse.urlencode({'email': 'hamlets-new@zulip.com'}), **host_kwargs)
result = client.patch('/json/settings',
urllib.parse.urlencode({'email': 'hamlets-new@zulip.com'}),
**host_kwargs)
assert result.status_code == 200

# Email change successful
key = Confirmation.objects.filter(type=Confirmation.EMAIL_CHANGE).latest('id').confirmation_key
url = confirmation_url(key, realm.host, Confirmation.EMAIL_CHANGE)
user_profile = get_user(registered_email, realm)
result = client.get(url)
assert result.status_code == 302
user_profile.emails = "hamlet@zulip.com"
user_profile.save()
assert result.status_code == 200

# Follow up day1 day2 emails
enqueue_welcome_emails(user_profile)
@@ -15,7 +15,7 @@ def process_unsubscribe(request: HttpRequest, confirmation_key: str, subscriptio
try:
user_profile = get_object_from_key(confirmation_key, Confirmation.UNSUBSCRIBE)
except ConfirmationKeyException as exception:
return render_confirmation_key_error(request, exception)
return render(request, 'zerver/unsubscribe_link_error.html')

unsubscribe_function(user_profile)
context = common_context(user_profile)
@@ -28,26 +28,22 @@
from confirmation.models import get_object_from_key, render_confirmation_key_error, \
ConfirmationKeyException, Confirmation

@zulip_login_required
def confirm_email_change(request, confirmation_key):
# type: (HttpRequest, str) -> HttpResponse
user_profile = request.user
if user_profile.realm.email_changes_disabled:
raise JsonableError(_("Email address changes are disabled in this organization."))

confirmation_key = confirmation_key.lower()
try:
obj = get_object_from_key(confirmation_key, Confirmation.EMAIL_CHANGE)
email_change_object = get_object_from_key(confirmation_key, Confirmation.EMAIL_CHANGE)
except ConfirmationKeyException as exception:
return render_confirmation_key_error(request, exception)

assert isinstance(obj, EmailChangeStatus)
new_email = obj.new_email
old_email = obj.old_email
new_email = email_change_object.new_email
old_email = email_change_object.old_email
user_profile = email_change_object.user_profile

do_change_user_email(obj.user_profile, obj.new_email)
if user_profile.realm.email_changes_disabled:
raise JsonableError(_("Email address changes are disabled in this organization."))
do_change_user_email(user_profile, new_email)

context = {'realm': obj.realm, 'new_email': new_email}
context = {'realm': user_profile.realm, 'new_email': new_email}
send_email('zerver/emails/notify_change_in_email', to_email=old_email,
from_name="Zulip Account Security", from_address=FromAddress.SUPPORT,
context=context)