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_custom_email: Add option for emailing sponsored org admins.

Tim Abbott123a46e41d7d
diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py
index 2b62d7514ed..05288483008 100644
--- a/zerver/management/commands/send_custom_email.py
+++ b/zerver/management/commands/send_custom_email.py
@@ -3,7 +3,7 @@ from typing import Any
from zerver.lib.management import CommandError, ZulipBaseCommand
from zerver.lib.send_email import send_custom_email
-from zerver.models import UserProfile
+from zerver.models import Realm, UserProfile
class Command(ZulipBaseCommand):
@@ -19,6 +19,11 @@ class Command(ZulipBaseCommand):
parser.add_argument(
"--entire-server", action="store_true", help="Send to every user on the server."
)
+ parser.add_argument(
+ "--all-sponsored-org-admins",
+ action="store_true",
+ help="Send to all organization administrators of sponsored organizations.",
+ )
parser.add_argument(
"--markdown-template-path",
"--path",
@@ -52,7 +57,24 @@ class Command(ZulipBaseCommand):
def handle(self, *args: Any, **options: str) -> None:
if options["entire_server"]:
- users = UserProfile.objects.filter(is_active=True, is_bot=False, is_mirror_dummy=False)
+ users = UserProfile.objects.filter(
+ is_active=True, is_bot=False, is_mirror_dummy=False, realm__deactivated=False
+ )
+ elif options["all_sponsored_org_admins"]:
+ # Sends at most one copy to each email address, even if it
+ # is an administrator in several organizations.
+ sponsored_realms = Realm.objects.filter(
+ plan_type=Realm.STANDARD_FREE, deactivated=False
+ )
+ admin_roles = [UserProfile.ROLE_REALM_ADMINISTRATOR, UserProfile.ROLE_REALM_OWNER]
+ users = UserProfile.objects.filter(
+ is_active=True,
+ is_bot=False,
+ is_mirror_dummy=False,
+ role__in=admin_roles,
+ realm__deactivated=False,
+ realm__in=sponsored_realms,
+ ).distinct("delivery_email")
else:
realm = self.get_realm(options)
try: