mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
management: Extract sync_user_from_ldap().
This commit is contained in:
committed by
Tim Abbott
parent
6e20a9a419
commit
348f370b79
@@ -11,7 +11,7 @@ from django.db.utils import IntegrityError
|
||||
from zerver.lib.logging_util import log_to_file
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.models import UserProfile
|
||||
from zproject.backends import ZulipLDAPUserPopulator, ZulipLDAPException
|
||||
from zproject.backends import ZulipLDAPException, sync_user_from_ldap
|
||||
|
||||
## Setup ##
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -20,12 +20,11 @@ log_to_file(logger, settings.LDAP_SYNC_LOG_PATH)
|
||||
# Run this on a cronjob to pick up on name changes.
|
||||
def sync_ldap_user_data(user_profiles: List[UserProfile]) -> None:
|
||||
logger.info("Starting update.")
|
||||
backend = ZulipLDAPUserPopulator()
|
||||
for u in user_profiles:
|
||||
# This will save the user if relevant, and will do nothing if the user
|
||||
# does not exist.
|
||||
try:
|
||||
if backend.populate_user(backend.django_to_ldap_username(u.email)) is not None:
|
||||
if sync_user_from_ldap(u):
|
||||
logger.info("Updated %s." % (u.email,))
|
||||
else:
|
||||
logger.warning("Did not find %s in LDAP." % (u.email,))
|
||||
|
||||
Reference in New Issue
Block a user