mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
email_change: Use HTML error for user deactivated error.
Currently when a deactivated user tries to access the change email link (generated when their account still active), a JSON error message will be shown. This adds a new portico error page for user deactivated errors. Now, `confirm_email_change` renders a portico error page when the user trying to change their email is deactivated. Fixes #20227.
This commit is contained in:
20
templates/zerver/portico_error_pages/user_deactivated.html
Normal file
20
templates/zerver/portico_error_pages/user_deactivated.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{% extends "zerver/portico_error_pages/portico_error_page.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
<title>{{ _("Account is deactivated") }} | Zulip</title>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block error_page_content %}
|
||||||
|
<img src="{{ static('images/errors/400art.svg') }}" alt=""/>
|
||||||
|
<div class="errorbox">
|
||||||
|
<div class="errorcontent">
|
||||||
|
<h1 class="lead">{{ _("Account is deactivated") }}</h1>
|
||||||
|
<p>
|
||||||
|
{% trans %}
|
||||||
|
Your Zulip account on <a href="{{ realm_url }}">{{ realm_url }}</a>
|
||||||
|
has been deactivated, and you will no longer be able to log in.
|
||||||
|
{% endtrans %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -155,6 +155,8 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||||||
do_deactivate_user(user_profile, acting_user=None)
|
do_deactivate_user(user_profile, acting_user=None)
|
||||||
response = self.client_get(activation_url)
|
response = self.client_get(activation_url)
|
||||||
self.assertEqual(response.status_code, 401)
|
self.assertEqual(response.status_code, 401)
|
||||||
|
error_page_title = "<title>Account is deactivated | Zulip</title>"
|
||||||
|
self.assert_in_response(error_page_title, response)
|
||||||
|
|
||||||
do_reactivate_user(user_profile, acting_user=None)
|
do_reactivate_user(user_profile, acting_user=None)
|
||||||
self.login_user(user_profile)
|
self.login_user(user_profile)
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ AVATAR_CHANGES_DISABLED_ERROR = gettext_lazy("Avatar changes are disabled in thi
|
|||||||
|
|
||||||
def validate_email_change_request(user_profile: UserProfile, new_email: str) -> None:
|
def validate_email_change_request(user_profile: UserProfile, new_email: str) -> None:
|
||||||
if not user_profile.is_active:
|
if not user_profile.is_active:
|
||||||
# TODO: Make this into a user-facing error, not JSON
|
|
||||||
raise UserDeactivatedError
|
raise UserDeactivatedError
|
||||||
|
|
||||||
if user_profile.realm.email_changes_disabled and not user_profile.is_realm_admin:
|
if user_profile.realm.email_changes_disabled and not user_profile.is_realm_admin:
|
||||||
@@ -110,8 +109,16 @@ def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpRes
|
|||||||
|
|
||||||
if user_profile.realm.deactivated:
|
if user_profile.realm.deactivated:
|
||||||
return redirect_to_deactivation_notice()
|
return redirect_to_deactivation_notice()
|
||||||
|
try:
|
||||||
validate_email_change_request(user_profile, new_email)
|
validate_email_change_request(user_profile, new_email)
|
||||||
|
except UserDeactivatedError:
|
||||||
|
context = {"realm_url": user_profile.realm.url}
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"zerver/portico_error_pages/user_deactivated.html",
|
||||||
|
context=context,
|
||||||
|
status=401,
|
||||||
|
)
|
||||||
do_change_user_delivery_email(user_profile, new_email, acting_user=user_profile)
|
do_change_user_delivery_email(user_profile, new_email, acting_user=user_profile)
|
||||||
|
|
||||||
user_profile = UserProfile.objects.get(id=email_change_object.user_profile_id)
|
user_profile = UserProfile.objects.get(id=email_change_object.user_profile_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user