Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
find-account: Send email when no Zulip accounts found.
swayam03225410df2a7bc7
diff --git a/templates/zerver/emails/find_team.html b/templates/zerver/emails/find_team.htmlindex 88f232792d7..64f4d16e151 100644--- a/templates/zerver/emails/find_team.html+++ b/templates/zerver/emails/find_team.html@@ -5,6 +5,7 @@{% endblock %}{% block content %}+{% if account_found %}<p>{{ _("Thanks for your request!") }}</p>{% if corporate_enabled %}@@ -22,6 +23,19 @@<p>{% trans %}If you have trouble logging in, you can <a href="{{ help_reset_password_link }}">reset your password</a>.{% endtrans %}</p>+{% else %}+<p>+ {{ _("You have requested a list of Zulip accounts for this email address.") }}+ {% if corporate_enabled %}+ {{ _("Unfortunately, no Zulip Cloud accounts were found.") }}+ {% else %}+ {% trans%}Unfortunately, no accounts were found in Zulip organizations hosted by {{external_host}}.{% endtrans %}+ {% endif %}+</p>-<p>{{ _("Thanks for using Zulip!") }}</p>+<p>+ {% trans %}You can <a href = "{{ find_accounts_link }}" >check for accounts</a> with another email, or <a href ="{{ help_logging_in_link }}">try another way</a> to find your account.{% endtrans %}+ {{ _("If you do not recognize this request, you can safely ignore this email.") }}+</p>+{% endif %}{% endblock %}diff --git a/templates/zerver/emails/find_team.subject.txt b/templates/zerver/emails/find_team.subject.txtindex d07a750aa08..f503bd364bd 100644--- a/templates/zerver/emails/find_team.subject.txt+++ b/templates/zerver/emails/find_team.subject.txt@@ -1 +1,5 @@-{{ _("Your Zulip accounts") }}+{% if account_found %}+ {{ _("Your Zulip accounts") }}+{% else %}+ {{ _("No Zulip accounts found") }}+{% endif %}diff --git a/templates/zerver/emails/find_team.txt b/templates/zerver/emails/find_team.txtindex 28af8cde868..26a41ae5663 100644--- a/templates/zerver/emails/find_team.txt+++ b/templates/zerver/emails/find_team.txt@@ -1,3 +1,4 @@+{% if account_found %}{{ _("Thanks for your request!") }}{% if corporate_enabled %}@@ -15,4 +16,21 @@{{ help_reset_password_link }}-{{ _("Thanks for using Zulip!") }}+{% else %}+{% if corporate_enabled %}+{{ _("You have requested a list of Zulip accounts for this email address.") }} {{ _("Unfortunately, no accounts in Zulip Cloud organizations were found.") }}++{% trans %}You can check for accounts with another email ({{ find_accounts_link }}), or try another way to find your account ({{ help_logging_in_link }}).{% endtrans %}+++{{ _("If you do not recognize this request, you can safely ignore this email.") }}+{% else %}+{{ _("You have requested a list of Zulip accounts for this email address.") }} {% trans%}Unfortunately, no accounts were found in Zulip organizations hosted by {{external_host}}.{% endtrans %}+++{% trans %}You can check for accounts with another email ({{ find_accounts_link }}), or try another way to find your account ({{ help_logging_in_link }}).{% endtrans %}+++{{ _("If you do not recognize this request, you can safely ignore this email.") }}+{% endif %}+{% endif %}diff --git a/templates/zerver/find_account.html b/templates/zerver/find_account.htmlindex 184aaed5ce5..1ea2aaced5e 100644--- a/templates/zerver/find_account.html+++ b/templates/zerver/find_account.html@@ -17,9 +17,7 @@<div id="results"><p>{% trans %}- Emails sent! You will only receive emails at addresses- associated with Zulip organizations. The addresses entered- on the previous page are listed below:+ Emails sent! The addresses entered on the previous page are listed below:{% endtrans %}</p>diff --git a/zerver/tests/test_i18n.py b/zerver/tests/test_i18n.pyindex ac9075e4ad7..678959aae33 100644--- a/zerver/tests/test_i18n.py+++ b/zerver/tests/test_i18n.py@@ -56,9 +56,7 @@ class EmailTranslationTestCase(ZulipTestCase):{"email": "[email protected]"},HTTP_ACCEPT_LANGUAGE="pt",)- check_translation(- "Danke, dass du", "post", "/accounts/find/", {"emails": hamlet.delivery_email}- )+ check_translation("Danke für", "post", "/accounts/find/", {"emails": hamlet.delivery_email})check_translation("Hallo","post",diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex cf87c0537e4..ecc18abb236 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -4253,7 +4253,7 @@ class TestFindMyTeam(ZulipTestCase):)self.assertEqual(result.status_code, 200)content = result.content.decode()- self.assertIn("Emails sent! You will only receive emails", content)+ self.assertIn("Emails sent! The addresses entered on", content)self.assertIn("[email protected]", content)self.assertIn("[email protected]", content)from django.core.mail import outbox@@ -4266,18 +4266,17 @@ class TestFindMyTeam(ZulipTestCase):self.assertIn("Zulip Dev", cordelia_message.body)self.assertIn("Lear & Co", cordelia_message.body)- def test_find_team_ignore_invalid_email(self) -> None:- result = self.client_post(- "/accounts/find/", dict(emails="[email protected],[email protected]")- )+ def test_find_team_email_with_no_account(self) -> None:+ result = self.client_post("/accounts/find/", dict(emails="[email protected]"))self.assertEqual(result.status_code, 200)content = result.content.decode()- self.assertIn("Emails sent! You will only receive emails", content)- self.assertIn(self.example_email("iago"), content)- self.assertIn("invalid_email@", content)+ self.assertIn("Emails sent! The addresses entered on", content)+ self.assertIn("no_account_email@", content)from django.core.mail import outboxself.assert_length(outbox, 1)+ message = outbox[0]+ self.assertIn("Unfortunately, no accounts", message.body)def test_find_team_reject_invalid_email(self) -> None:result = self.client_post("/accounts/find/", dict(emails="invalid_string"))@@ -4307,6 +4306,8 @@ class TestFindMyTeam(ZulipTestCase):from django.core.mail import outboxself.assert_length(outbox, 1)+ message = outbox[0]+ self.assertIn("Zulip Dev", message.body)def test_find_team_deactivated_user(self) -> None:do_deactivate_user(self.example_user("hamlet"), acting_user=None)@@ -4315,7 +4316,9 @@ class TestFindMyTeam(ZulipTestCase):self.assertEqual(result.status_code, 200)from django.core.mail import outbox- self.assert_length(outbox, 0)+ self.assert_length(outbox, 1)+ message = outbox[0]+ self.assertIn("Unfortunately, no accounts", message.body)def test_find_team_deactivated_realm(self) -> None:do_deactivate_realm(get_realm("zulip"), acting_user=None)@@ -4324,7 +4327,9 @@ class TestFindMyTeam(ZulipTestCase):self.assertEqual(result.status_code, 200)from django.core.mail import outbox- self.assert_length(outbox, 0)+ self.assert_length(outbox, 1)+ message = outbox[0]+ self.assertIn("Unfortunately, no accounts", message.body)def test_find_team_bot_email(self) -> None:data = {"emails": self.example_email("webhook_bot")}@@ -4332,7 +4337,9 @@ class TestFindMyTeam(ZulipTestCase):self.assertEqual(result.status_code, 200)from django.core.mail import outbox- self.assert_length(outbox, 0)+ self.assert_length(outbox, 1)+ message = outbox[0]+ self.assertIn("Unfortunately, no accounts", message.body)def test_find_team_more_than_ten_emails(self) -> None:data = {"emails": ",".join(f"hamlet-{i}@zulip.com" for i in range(11))}diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex eeb4d175d45..16478d3f068 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -1,6 +1,6 @@import loggingfrom contextlib import suppress-from typing import Any, Dict, Iterable, List, Optional, Tuple, Union+from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Unionfrom urllib.parse import urlencode, urljoinimport orjson@@ -1134,6 +1134,7 @@ def find_account(request: HttpRequest) -> HttpResponse:# one outgoing email per provided email address, with each# email listing all of the accounts that email address has# with the current Zulip server.+ emails_account_found: Set[str] = set()context: Dict[str, Dict[str, Any]] = {}for user in user_profiles:key = user.delivery_email.lower()@@ -1144,6 +1145,7 @@ def find_account(request: HttpRequest) -> HttpResponse:# matching accounts; since it's only used for minor# details like language, that arbitrary choice is OK.context[key]["to_user_id"] = user.id+ emails_account_found.add(user.delivery_email)# Links in find_team emails use the server's information# and not any particular realm's information.@@ -1152,12 +1154,15 @@ def find_account(request: HttpRequest) -> HttpResponse:help_reset_password_link = (f"{help_base_url}/change-your-password#if-youve-forgotten-or-never-had-a-password")+ help_logging_in_link = f"{help_base_url}/logging-in#find-the-zulip-log-in-url"+ find_accounts_link = f"{external_host_base_url}/accounts/find/"for delivery_email, realm_context in context.items():send_email("zerver/emails/find_team",to_user_ids=[realm_context["to_user_id"]],context={+ "account_found": True,"external_host": settings.EXTERNAL_HOST,"corporate_enabled": settings.CORPORATE_ENABLED,"help_reset_password_link": help_reset_password_link,@@ -1167,6 +1172,27 @@ def find_account(request: HttpRequest) -> HttpResponse:from_address=FromAddress.SUPPORT,request=request,)++ emails_lower_with_account = {email.lower() for email in emails_account_found}+ emails_without_account: Set[str] = {+ email for email in emails if email.lower() not in emails_lower_with_account+ }+ if emails_without_account:+ send_email(+ "zerver/emails/find_team",+ to_emails=list(emails_without_account),+ context=(+ {+ "account_found": False,+ "external_host": settings.EXTERNAL_HOST,+ "corporate_enabled": settings.CORPORATE_ENABLED,+ "find_accounts_link": find_accounts_link,+ "help_logging_in_link": help_logging_in_link,+ }+ ),+ from_address=FromAddress.SUPPORT,+ request=request,+ )return render(request,"zerver/find_account.html",