From 5b1387c9ba30a0eba5aa39733023f99d6e71efb4 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 4 Jan 2024 15:23:25 +0000 Subject: [PATCH] send_password_reset_email: Add a flag to only email users who need it. Emailing the password reset email to users who have already logged in is not as useful. --- help/include/import-how-users-will-log-in.md | 7 +++++++ .../management/commands/send_password_reset_email.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/help/include/import-how-users-will-log-in.md b/help/include/import-how-users-will-log-in.md index b548fbf084..3a1c47772a 100644 --- a/help/include/import-how-users-will-log-in.md +++ b/help/include/import-how-users-will-log-in.md @@ -62,6 +62,13 @@ If you imported your organization into Zulip Cloud, simply e-mail ./manage.py send_password_reset_email -r --all-users ``` + If you would like to only send emails to users who have not logged in yet, + you can use the following variant instead: + + ``` + ./manage.py send_password_reset_email -r --all-users --only-never-logged-in + ``` + {end_tabs} ### Manual password resets diff --git a/zerver/management/commands/send_password_reset_email.py b/zerver/management/commands/send_password_reset_email.py index 0f47250e0a..8cab2a7bbc 100644 --- a/zerver/management/commands/send_password_reset_email.py +++ b/zerver/management/commands/send_password_reset_email.py @@ -17,6 +17,11 @@ class Command(ZulipBaseCommand): @override def add_arguments(self, parser: ArgumentParser) -> None: + parser.add_argument( + "--only-never-logged-in", + action="store_true", + help="Filter to only users which have not accepted the TOS.", + ) parser.add_argument( "--entire-server", action="store_true", help="Send to every user on the server. " ) @@ -43,6 +48,11 @@ class Command(ZulipBaseCommand): "You have to pass -u/--users or -a/--all-users or --entire-server." ) raise error + if options["only_never_logged_in"]: + users = users.filter(tos_version=-1) + + if not users.exists(): + print("No matching users!") self.send(users)