mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
send_custom_email: Add support for emailing all admins.
This provides a convenient way to send a custom email to just the administrators of an organization. Fixes part of #13413.
This commit is contained in:
@@ -295,7 +295,8 @@ def send_custom_email(users: List[UserProfile], options: Dict[str, Any]) -> None
|
|||||||
inline_template(email_filename)
|
inline_template(email_filename)
|
||||||
|
|
||||||
# Finally, we send the actual emails.
|
# Finally, we send the actual emails.
|
||||||
for user_profile in users:
|
for user_profile in filter(lambda user:
|
||||||
|
not options.get('admins_only') or user.is_realm_admin, users):
|
||||||
context = {
|
context = {
|
||||||
'realm_uri': user_profile.realm.uri,
|
'realm_uri': user_profile.realm.uri,
|
||||||
'realm_name': user_profile.realm.name,
|
'realm_name': user_profile.realm.name,
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class Command(ZulipBaseCommand):
|
|||||||
parser.add_argument('--reply-to',
|
parser.add_argument('--reply-to',
|
||||||
type=str,
|
type=str,
|
||||||
help='Optional reply-to line for the email')
|
help='Optional reply-to line for the email')
|
||||||
|
parser.add_argument('--admins-only',
|
||||||
|
help='Send only to organization administrators',
|
||||||
|
action='store_true')
|
||||||
|
|
||||||
self.add_user_list_args(parser,
|
self.add_user_list_args(parser,
|
||||||
help="Email addresses of user(s) to send emails to.",
|
help="Email addresses of user(s) to send emails to.",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from typing import List, Optional
|
|||||||
|
|
||||||
from zerver.lib.email_notifications import fix_emojis, handle_missedmessage_emails, \
|
from zerver.lib.email_notifications import fix_emojis, handle_missedmessage_emails, \
|
||||||
enqueue_welcome_emails, relative_to_full_url
|
enqueue_welcome_emails, relative_to_full_url
|
||||||
from zerver.lib.actions import do_change_notification_settings
|
from zerver.lib.actions import do_change_notification_settings, do_change_is_admin
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.lib.send_email import FromAddress, send_custom_email
|
from zerver.lib.send_email import FromAddress, send_custom_email
|
||||||
from zerver.models import (
|
from zerver.models import (
|
||||||
@@ -89,6 +89,20 @@ class TestCustomEmails(ZulipTestCase):
|
|||||||
"from_name": from_name,
|
"from_name": from_name,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def test_send_custom_email_admins_only(self) -> None:
|
||||||
|
admin_user = self.example_user('hamlet')
|
||||||
|
do_change_is_admin(admin_user, True)
|
||||||
|
|
||||||
|
non_admin_user = self.example_user('cordelia')
|
||||||
|
|
||||||
|
markdown_template_path = "zerver/tests/fixtures/email/custom_emails/email_base_headers_test.source.html"
|
||||||
|
send_custom_email([admin_user, non_admin_user], {
|
||||||
|
"markdown_template_path": markdown_template_path,
|
||||||
|
"admins_only": True
|
||||||
|
})
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
self.assertIn(admin_user.delivery_email, mail.outbox[0].to[0])
|
||||||
|
|
||||||
|
|
||||||
class TestFollowupEmails(ZulipTestCase):
|
class TestFollowupEmails(ZulipTestCase):
|
||||||
def test_day1_email_context(self) -> None:
|
def test_day1_email_context(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user