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:
PieterCK
2025-03-24 18:06:17 +07:00
committed by Tim Abbott
parent 8fab9a23ce
commit cc39b6860b
3 changed files with 32 additions and 3 deletions

View File

@@ -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:
if not user_profile.is_active:
# TODO: Make this into a user-facing error, not JSON
raise UserDeactivatedError
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:
return redirect_to_deactivation_notice()
validate_email_change_request(user_profile, new_email)
try:
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)
user_profile = UserProfile.objects.get(id=email_change_object.user_profile_id)