fix: 修改LDAP用户导入默认添加到Default组织

pull/6279/head
Bai 2021-06-16 10:43:48 +08:00 committed by Jiangjie.Bai
parent 5263a146e2
commit b115ed3b79
1 changed files with 7 additions and 1 deletions

View File

@ -26,6 +26,7 @@ from common.const import LDAP_AD_ACCOUNT_DISABLE
from common.utils import timeit, get_logger
from users.utils import construct_user_email
from users.models import User
from orgs.models import Organization
from authentication.backends.ldap import LDAPAuthorizationBackend, LDAPUser
logger = get_logger(__file__)
@ -364,12 +365,17 @@ class LDAPImportUtil(object):
def perform_import(self, users):
logger.info('Start perform import ldap users, count: {}'.format(len(users)))
errors = []
instances = []
for user in users:
try:
self.update_or_create(user)
obj, created = self.update_or_create(user)
if created:
instances.append(user)
except Exception as e:
errors.append({user['username']: str(e)})
logger.error(e)
# 默认添加用户到 Default 组织
Organization.default().members.add(*instances)
logger.info('End perform import ldap users')
return errors