Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

send_email: Broaden type of context dict.

Alex Vandiverc2c67a76408b
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.py
index a55add60484..9d47a3b59a3 100644
--- a/zerver/lib/send_email.py
+++ b/zerver/lib/send_email.py
@@ -510,7 +510,7 @@ def send_custom_email(
*,
target_emails: Sequence[str] = [],
options: Dict[str, Any],
- add_context: Optional[Callable[[Dict[str, Union[List[str], str]], UserProfile], None]] = None,
+ add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None,
) -> None:
"""
Helper for `manage.py send_custom_email`.
@@ -562,7 +562,7 @@ def send_custom_email(
for user_profile in users.select_related("realm").order_by("id"):
if options.get("admins_only") and not user_profile.is_realm_admin:
continue
- context: Dict[str, Union[List[str], str]] = {
+ context: Dict[str, object] = {
"realm_uri": user_profile.realm.uri,
"realm_name": user_profile.realm.name,
}
diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py
index 9d4af230c91..863088f0112 100644
--- a/zerver/management/commands/send_custom_email.py
+++ b/zerver/management/commands/send_custom_email.py
@@ -1,5 +1,5 @@
from argparse import ArgumentParser
-from typing import Any, Callable, Dict, List, Optional, Union
+from typing import Any, Callable, Dict, List, Optional
import orjson
from django.conf import settings
@@ -86,9 +86,7 @@ class Command(ZulipBaseCommand):
def handle(self, *args: Any, **options: str) -> None:
target_emails: List[str] = []
users: QuerySet[UserProfile] = UserProfile.objects.none()
- add_context: Optional[
- Callable[[Dict[str, Union[List[str], str]], UserProfile], None]
- ] = None
+ add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None
if options["entire_server"]:
users = UserProfile.objects.filter(
@@ -106,9 +104,7 @@ class Command(ZulipBaseCommand):
long_term_idle=False,
).distinct("delivery_email")
- def add_marketing_unsubscribe(
- context: Dict[str, Union[List[str], str]], user: UserProfile
- ) -> None:
+ def add_marketing_unsubscribe(context: Dict[str, object], user: UserProfile) -> None:
context["unsubscribe_link"] = one_click_unsubscribe_link(user, "marketing")
add_context = add_marketing_unsubscribe
@@ -139,12 +135,10 @@ class Command(ZulipBaseCommand):
).distinct("delivery_email")
elif options["json_file"]:
with open(options["json_file"]) as f:
- user_data: Dict[str, Dict[str, Union[List[str], str]]] = orjson.loads(f.read())
+ user_data: Dict[str, Dict[str, object]] = orjson.loads(f.read())
users = UserProfile.objects.filter(id__in=[int(user_id) for user_id in user_data])
- def add_context_from_dict(
- context: Dict[str, Union[List[str], str]], user: UserProfile
- ) -> None:
+ def add_context_from_dict(context: Dict[str, object], user: UserProfile) -> None:
context.update(user_data.get(str(user.id), {}))
add_context = add_context_from_dict
diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.py
index 05ff3204aa2..053edaa825a 100644
--- a/zerver/tests/test_email_notifications.py
+++ b/zerver/tests/test_email_notifications.py
@@ -1,6 +1,6 @@
import tempfile
from datetime import datetime, timedelta, timezone
-from typing import Dict, List, Union
+from typing import Dict
from unittest.mock import patch
import ldap
@@ -130,7 +130,7 @@ class TestCustomEmails(ZulipTestCase):
"zerver/tests/fixtures/email/custom_emails/email_base_headers_custom_test.md"
)
- def add_context(context: Dict[str, Union[List[str], str]], user: UserProfile) -> None:
+ def add_context(context: Dict[str, object], user: UserProfile) -> None:
context["unsubscribe_link"] = "some@email"
context["custom"] = str(user.id)