mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +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.logging_util import log_to_file
|
||||||
from zerver.lib.management import ZulipBaseCommand
|
from zerver.lib.management import ZulipBaseCommand
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
from zproject.backends import ZulipLDAPUserPopulator, ZulipLDAPException
|
from zproject.backends import ZulipLDAPException, sync_user_from_ldap
|
||||||
|
|
||||||
## Setup ##
|
## Setup ##
|
||||||
logger = logging.getLogger(__name__)
|
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.
|
# Run this on a cronjob to pick up on name changes.
|
||||||
def sync_ldap_user_data(user_profiles: List[UserProfile]) -> None:
|
def sync_ldap_user_data(user_profiles: List[UserProfile]) -> None:
|
||||||
logger.info("Starting update.")
|
logger.info("Starting update.")
|
||||||
backend = ZulipLDAPUserPopulator()
|
|
||||||
for u in user_profiles:
|
for u in user_profiles:
|
||||||
# This will save the user if relevant, and will do nothing if the user
|
# This will save the user if relevant, and will do nothing if the user
|
||||||
# does not exist.
|
# does not exist.
|
||||||
try:
|
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,))
|
logger.info("Updated %s." % (u.email,))
|
||||||
else:
|
else:
|
||||||
logger.warning("Did not find %s in LDAP." % (u.email,))
|
logger.warning("Did not find %s in LDAP." % (u.email,))
|
||||||
|
|||||||
@@ -414,6 +414,11 @@ class ZulipLDAPUserPopulator(ZulipLDAPAuthBackendBase):
|
|||||||
return_data: Optional[Dict[str, Any]]=None) -> None:
|
return_data: Optional[Dict[str, Any]]=None) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def sync_user_from_ldap(user_profile: UserProfile) -> bool:
|
||||||
|
backend = ZulipLDAPUserPopulator()
|
||||||
|
updated_user = backend.populate_user(backend.django_to_ldap_username(user_profile.email))
|
||||||
|
return updated_user is not None
|
||||||
|
|
||||||
class DevAuthBackend(ZulipAuthMixin):
|
class DevAuthBackend(ZulipAuthMixin):
|
||||||
# Allow logging in as any user without a password.
|
# Allow logging in as any user without a password.
|
||||||
# This is used for convenience when developing Zulip.
|
# This is used for convenience when developing Zulip.
|
||||||
|
|||||||
Reference in New Issue
Block a user