From 323152c5fdc150c1b64fd67a91da60bbd4a800ed Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 19 May 2021 13:42:49 -0700 Subject: [PATCH] send_custom_email: Never email users who haven't agreed to ToS. The `create_user` API and data import tools can result in our having active users in the database who haven't intentionally created a Zulip account or agreed to the ToS; we should never email such users. The check for `TOS_VERSION is not None` is necessary for the development environment, which has `TERMS_OF_SERVICE` set but not `TOS_VERSION`. It's likely that we will want this check in other places as well. --- zerver/management/commands/send_custom_email.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py index 5947fd5b99..3dc2c79ad3 100644 --- a/zerver/management/commands/send_custom_email.py +++ b/zerver/management/commands/send_custom_email.py @@ -1,6 +1,8 @@ from argparse import ArgumentParser from typing import Any +from django.conf import settings + from zerver.lib.management import CommandError, ZulipBaseCommand from zerver.lib.send_email import send_custom_email from zerver.models import Realm, UserProfile @@ -86,6 +88,9 @@ class Command(ZulipBaseCommand): ) raise error + # Only email users who've agreed to the terms of service. + if settings.TOS_VERSION is not None: + users = users.exclude(tos_version=None) send_custom_email(users, options) if options["dry_run"]: