Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
send_custom_email: Add a flag for sending release announcements.
Alex Vandiverfdcfafd13db2
diff --git a/templates/zerver/emails/custom_email_base.pre.html b/templates/zerver/emails/custom_email_base.pre.htmlindex 9eb792aa133..42287231f08 100644--- a/templates/zerver/emails/custom_email_base.pre.html+++ b/templates/zerver/emails/custom_email_base.pre.html@@ -13,9 +13,13 @@{% block manage_preferences %}{% if remote_server_email %}- <p>You are receiving this email to update you about important changes to Zulip's Terms of Service.</p>- <a href="{{ unsubscribe_link }}">Unsubscribe</a>+ {% if released_version %}+ <p>You are receiving this email because you opted into release notifications.</p>+ {% else %}+ <p>You are receiving this email to update you about important changes to Zulip's Terms of Service.</p>+ <a href="{{ unsubscribe_link }}">Unsubscribe</a>+ {% endif %}{% elif unsubscribe_link %}- <p><a href="{{ realm_url }}/#settings/notifications">{{ _("Manage email preferences") }}</a> | <a href="{{ unsubscribe_link }}">{{ _("Unsubscribe from marketing emails") }}</a></p>+ <p><a href="{{ realm_url }}/#settings/notifications">{{ _("Manage email preferences") }}</a> | <a href="{{ unsubscribe_link }}">{{ _("Unsubscribe from marketing emails") }}</a></p>{% endif %}{% endblock %}diff --git a/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt b/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txtindex 37d3c97e3a4..36b36d95cb2 100644--- a/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt+++ b/templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt@@ -1,9 +1,13 @@---{% if remote_server_email %}+{% if released_version %}+You are receiving this email because you opted into release notifications.+{% else %}You are receiving this email to update you about important changes to Zulip's Terms of Service.Unsubscribe: {{ unsubscribe_link }}+{% endif %}{% elif unsubscribe_link %}{{ _("Manage email preferences") }}:diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.pyindex 766d5959069..63fa4a0584d 100644--- a/zerver/management/commands/send_custom_email.py+++ b/zerver/management/commands/send_custom_email.py@@ -9,11 +9,12 @@ from typing_extensions import overridefrom confirmation.models import one_click_unsubscribe_linkfrom zerver.lib.management import ZulipBaseCommand-from zerver.lib.send_email import send_custom_email, send_custom_server_email+from zerver.lib.send_email import custom_email_sender, send_custom_email, send_custom_server_emailfrom zerver.models import Realm, UserProfileif settings.ZILENCER_ENABLED:- from zilencer.models import RemoteZulipServer+ from corporate.lib.stripe import BILLING_SUPPORT_EMAIL+ from zilencer.models import RemoteRealmBillingUser, RemoteServerBillingUser, RemoteZulipServerclass Command(ZulipBaseCommand):@@ -41,6 +42,11 @@ class Command(ZulipBaseCommand):action="store_true",help="Send to registered contact email addresses for remote Zulip servers.",)+ targets.add_argument(+ "--announce-release",+ metavar="VERSION",+ help="Announce a major or minor release to remote servers.",+ )targets.add_argument("--all-sponsored-org-admins",action="store_true",@@ -133,6 +139,45 @@ class Command(ZulipBaseCommand):for server in servers:print(f" {server.contact_email} ({server.hostname})")return+ elif options["announce_release"]:+ server_users = RemoteServerBillingUser.objects.filter(+ is_active=True,+ remote_server__deactivated=False,+ )+ realm_users = RemoteRealmBillingUser.objects.filter(+ is_active=True,+ remote_realm__server__deactivated=False,+ remote_realm__is_system_bot_realm=False,+ remote_realm__registration_deactivated=False,+ remote_realm__realm_deactivated=False,+ remote_realm__realm_locally_deleted=False,+ )+ if options["announce_release"].endswith(".0"):+ server_users = server_users.filter(enable_major_release_emails=True)+ realm_users = realm_users.filter(enable_major_release_emails=True)+ else:+ server_users = server_users.filter(enable_maintenance_release_emails=True)+ realm_users = realm_users.filter(enable_maintenance_release_emails=True)+ # This does an implicit "distinct"+ all_emails = server_users.union(realm_users).values_list("email", flat=True)+ del options["from_address"]+ email_sender = custom_email_sender(+ dry_run=dry_run, from_address=BILLING_SUPPORT_EMAIL, **options+ )++ for email in all_emails:+ email_sender(+ to_email=email,+ context={+ "remote_server_email": True,+ "released_version": options["announce_release"],+ },+ )+ if dry_run:+ print("Would send the above email to:")+ for email in all_emails:+ print(f" {email}")+ returnif options["entire_server"]:users = UserProfile.objects.filter(