admin: Added realm option to prevent users from changing their email.

A realm option to prevent users from changing their email address is added.
Fixes #3777.
This commit is contained in:
Raghav Jajodia
2017-03-04 11:09:45 +05:30
committed by Tim Abbott
parent d25bfb88d3
commit cd2d798498
14 changed files with 149 additions and 3 deletions

View File

@@ -38,6 +38,10 @@ from confirmation.models import EmailChangeConfirmation
@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 change disabled"))
confirmation_key = confirmation_key.lower()
obj = EmailChangeConfirmation.objects.confirm(confirmation_key)
confirmed = False
@@ -128,6 +132,8 @@ def json_change_settings(request, user_profile,
result = {}
new_email = email.strip()
if user_profile.email != email and new_email != '':
if user_profile.realm.email_changes_disabled:
return json_error(_("Email change is disabled!"))
error, skipped = validate_email(user_profile, new_email)
if error or skipped:
return json_error(error or skipped)