management: Fix password reset emails being sent to deactivated users.

Apparently, the filters written for the send_password_reset_email (and
some other management commands) didn't correctly consider the case of
deactivated users.

While some commands, like syncing LDAP data (which can include whether
a user should be deactivated) want to process all users, other
commands generally only want to interact with active users.  We fix
this and add some tests.
This commit is contained in:
Tim Abbott
2019-08-14 10:48:54 -07:00
parent cbae51db63
commit 2ada0a9bad
4 changed files with 32 additions and 7 deletions

View File

@@ -41,7 +41,8 @@ class Command(ZulipBaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
if options.get('realm_id') is not None:
realm = self.get_realm(options)
user_profiles = self.get_users(options, realm, is_bot=False)
user_profiles = self.get_users(options, realm, is_bot=False,
include_deactivated=True)
else:
user_profiles = UserProfile.objects.select_related().filter(is_bot=False)
sync_ldap_user_data(user_profiles)