Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
sync_ldap_user_data: Show a proper error if no relevant users exist.
Mateusz Manderac8fee0652141
diff --git a/zerver/management/commands/sync_ldap_user_data.py b/zerver/management/commands/sync_ldap_user_data.pyindex 1227067d3cb..8384ee7c333 100644--- a/zerver/management/commands/sync_ldap_user_data.py+++ b/zerver/management/commands/sync_ldap_user_data.py@@ -3,6 +3,7 @@ from argparse import ArgumentParserfrom typing import Any, Listfrom django.conf import settings+from django.core.management.base import CommandErrorfrom django.db import transactionfrom zerver.lib.logging_util import log_to_file@@ -76,5 +77,18 @@ class Command(ZulipBaseCommand):realm = self.get_realm(options)user_profiles = self.get_users(options, realm, is_bot=False, include_deactivated=True)else:- user_profiles = UserProfile.objects.select_related().filter(is_bot=False)+ user_profile_query = UserProfile.objects.select_related().filter(is_bot=False)++ if not user_profile_query.exists():+ # This case provides a special error message if one+ # tries setting up LDAP sync before creating a realm.+ raise CommandError("Zulip server contains no users. Have you created a realm?")+ user_profiles = list(user_profile_query)++ if len(user_profiles) == 0:+ # We emphasize that this error is purely about the+ # command-line parameters, since this has nothing to do+ # with your LDAP configuration.+ raise CommandError("Zulip server contains no users matching command-line parameters.")+sync_ldap_user_data(user_profiles, not options["force"])