emails/password_reset: Change template string for deactivated users.

This commit is contained in:
Shubham Dhama 2018-08-16 21:40:11 +05:30 committed by Tim Abbott
parent 491bd6d2c9
commit aa8b3d2beb
4 changed files with 29 additions and 9 deletions

View File

@ -9,10 +9,17 @@
</p>
{% else %}
<p>
{% if user_deactivated %}
Someone (possibly you) requested a password reset email for {{ email }}
on {{ realm_uri }}, but you do not have an
active account in {{ realm_uri }}.
on {{ realm_uri }}, but your account has been deactivated. You can contact
an organization administrator to reactivate your account.
{% else %}
Someone (possibly you) requested a password reset email for {{ email }}
on {{ realm_uri }}, but you do not have an account in that organization.
{% endif %}
</p>
<p>
{% if active_accounts %}
{% if multiple_active_accounts %}
However, you do have active accounts in the following

View File

@ -5,9 +5,14 @@ It's all good. Follow the link below and we'll take care of the rest:
{{ reset_url }}
{% else %}
Someone (possibly you) requested a password reset email for
{{ email }} on {{ realm_uri }}, but
you do not have an active account in {{ realm_uri }}.
{% if user_deactivated %}
Someone (possibly you) requested a password reset email for {{ email }}
on {{ realm_uri }}, but your account has been deactivated. You can contact
an organization administrator to reactivate your account.
{% else %}
Someone (possibly you) requested a password reset email for {{ email }}
on {{ realm_uri }}, but you do not have an account in that organization.
{% endif %}
{% if active_accounts %}
{% if multiple_active_accounts %}
However, you do have active accounts in the following organizations.

View File

@ -24,7 +24,7 @@ from zerver.lib.request import JsonableError
from zerver.lib.send_email import send_email, FromAddress
from zerver.lib.subdomains import get_subdomain, user_matches_subdomain, is_root_domain_available
from zerver.lib.users import check_full_name
from zerver.models import Realm, get_active_user, UserProfile, get_realm, email_to_domain, \
from zerver.models import Realm, get_user, UserProfile, get_realm, email_to_domain, \
email_allowed_for_realm, DisposableEmailError, DomainNotAllowedForRealmError, \
EmailContainsPlusError
from zproject.backends import email_auth_enabled, email_belongs_to_ldap
@ -226,7 +226,7 @@ class ZulipPasswordResetForm(PasswordResetForm):
user = None # type: Optional[UserProfile]
try:
user = get_active_user(email, realm)
user = get_user(email, realm)
except UserProfile.DoesNotExist:
pass
@ -235,6 +235,10 @@ class ZulipPasswordResetForm(PasswordResetForm):
'realm_uri': realm.uri,
}
if user is not None and not user.is_active:
context['user_deactivated'] = True
user = None
if user is not None:
token = token_generator.make_token(user)
uid = urlsafe_base64_encode(force_bytes(user.id)).decode('ascii')

View File

@ -260,6 +260,8 @@ class PasswordResetTest(ZulipTestCase):
outbox[0].body)
self.assertNotIn('does have an active account in the zulip.testserver',
outbox[0].body)
self.assertIn('but your account has been deactivated',
outbox[0].body)
def test_password_reset_with_deactivated_realm(self) -> None:
user_profile = self.example_user("hamlet")
@ -304,9 +306,11 @@ class PasswordResetTest(ZulipTestCase):
message = outbox.pop()
tokenized_no_reply_email = parseaddr(message.from_email)[1]
self.assertTrue(re.search(self.TOKENIZED_NOREPLY_REGEX, tokenized_no_reply_email))
self.assertIn('Someone (possibly you) requested a password',
self.assertIn('Someone (possibly you) requested a password reset email for',
message.body)
self.assertIn("but\nyou do not have an active account in http://zephyr.testserver",
self.assertIn("but you do not have an account in that organization",
message.body)
self.assertIn("However, you do have an active account in the http://zulip.testserver\norganization;",
message.body)
def test_invalid_subdomain(self) -> None: