From 4b7cd79682cf92cf43c4daa059f6df90d2af9873 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Fri, 27 Sep 2019 14:04:10 +0800 Subject: [PATCH] =?UTF-8?q?[Feature]=20=E6=B7=BB=E5=8A=A0=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=20LDAP/AD=20=E7=94=A8=E6=88=B7=E7=9A=84=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/settings/utils.py | 2 +- apps/users/tasks.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/settings/utils.py b/apps/settings/utils.py index 7fc7510dd..b66e66a38 100644 --- a/apps/settings/utils.py +++ b/apps/settings/utils.py @@ -186,7 +186,7 @@ class LDAPUtil: result = {'total': len(user_items), 'succeed': succeed, 'failed': failed} return result - def sync_users(self, username_list): + def sync_users(self, username_list=None): user_items = self.search_filter_user_items(username_list) result = self.create_or_update_users(user_items) return result diff --git a/apps/users/tasks.py b/apps/users/tasks.py index cbdfd4848..6c6faf603 100644 --- a/apps/users/tasks.py +++ b/apps/users/tasks.py @@ -10,6 +10,8 @@ from .models import User from .utils import ( send_password_expiration_reminder_mail, send_user_expiration_reminder_mail ) +from settings.utils import LDAPUtil +from django.conf import settings logger = get_logger(__file__) @@ -66,3 +68,26 @@ def check_user_expired_periodic(): } create_or_update_celery_periodic_tasks(tasks) + +@shared_task +def sync_ldap_user(): + logger.info("Start sync ldap user periodic task") + util = LDAPUtil() + result = util.sync_users() + logger.info("Result: {}".format(result)) + + +@shared_task +@after_app_ready_start +def sync_ldap_user_periodic(): + if not settings.AUTH_LDAP: + return + tasks = { + 'sync_ldap_user_periodic': { + 'task': sync_ldap_user.name, + 'interval': None, + 'crontab': '* * * * *', + 'enabled': True, + } + } + create_or_update_celery_periodic_tasks(tasks)