Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
send_email: Pull admins_only back into send_custom_email filtering.
Alex Vandiver62e6b10ecd96
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.pyindex b20ff8e65b8..4761916809b 100644--- a/zerver/lib/send_email.py+++ b/zerver/lib/send_email.py@@ -513,7 +513,6 @@ def send_custom_email(target_emails: Sequence[str] = [],dry_run: bool,options: Dict[str, str],- admins_only: bool = False,add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None,) -> None:"""@@ -564,8 +563,6 @@ def send_custom_email(# Finally, we send the actual emails.for user_profile in users.select_related("realm").order_by("id"):- if admins_only and not user_profile.is_realm_admin:- continuecontext: Dict[str, object] = {"realm": user_profile.realm,"realm_string_id": user_profile.realm.string_id,diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.pyindex a27f311d944..966bf5fba9d 100644--- a/zerver/management/commands/send_custom_email.py+++ b/zerver/management/commands/send_custom_email.py@@ -152,6 +152,9 @@ class Command(ZulipBaseCommand):realm = self.get_realm(options)users = self.get_users(options, realm, is_bot=False)+ if admins_only:+ users = users.filter(is_realm_admin=True)+# Only email users who've agreed to the terms of service.if settings.TERMS_OF_SERVICE_VERSION is not None:users = users.exclude(@@ -161,7 +164,6 @@ class Command(ZulipBaseCommand):users,target_emails=target_emails,dry_run=dry_run,- admins_only=admins_only,options=options,add_context=add_context,)diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.pyindex 47fed107a74..eaa909c193a 100644--- a/zerver/tests/test_email_notifications.py+++ b/zerver/tests/test_email_notifications.py@@ -11,7 +11,6 @@ from django.test import override_settingsfrom django.utils.timezone import now as timezone_nowfrom django_auth_ldap.config import LDAPSearch-from zerver.actions.users import do_change_user_rolefrom zerver.lib.email_notifications import (enqueue_welcome_emails,get_onboarding_email_schedule,@@ -212,26 +211,6 @@ class TestCustomEmails(ZulipTestCase):},)- def test_send_custom_email_admins_only(self) -> None:- admin_user = self.example_user("hamlet")- do_change_user_role(admin_user, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)-- non_admin_user = self.example_user("cordelia")-- markdown_template_path = (- "zerver/tests/fixtures/email/custom_emails/email_base_headers_test.md"- )- send_custom_email(- UserProfile.objects.filter(id__in=(admin_user.id, non_admin_user.id)),- dry_run=False,- admins_only=True,- options={- "markdown_template_path": markdown_template_path,- },- )- self.assert_length(mail.outbox, 1)- self.assertIn(admin_user.delivery_email, mail.outbox[0].to[0])-def test_send_custom_email_dry_run(self) -> None:hamlet = self.example_user("hamlet")email_subject = "subject_test"