perf: ldap 能多组织同步用户 (#10543)

Co-authored-by: feng <1304903146@qq.com>
Co-authored-by: feng626 <57284900+feng626@users.noreply.github.com>
This commit is contained in:
fit2bot
2023-05-25 17:35:36 +08:00
committed by GitHub
parent fa21c83db3
commit a6366a2dd4
9 changed files with 72 additions and 36 deletions

View File

@@ -191,13 +191,13 @@ class LDAPUserImportAPI(APIView):
'POST': 'settings.change_auth'
}
def get_org(self):
org_id = self.request.data.get('org_id')
if is_uuid(org_id):
org = Organization.objects.get(id=org_id)
def get_orgs(self):
org_ids = self.request.data.get('org_ids')
if org_ids:
orgs = list(Organization.objects.filter(id__in=org_ids))
else:
org = current_org
return org
orgs = [current_org]
return orgs
def get_ldap_users(self):
username_list = self.request.data.get('username_list', [])
@@ -219,14 +219,15 @@ class LDAPUserImportAPI(APIView):
if users is None:
return Response({'msg': _('Get ldap users is None')}, status=400)
org = self.get_org()
errors = LDAPImportUtil().perform_import(users, org)
orgs = self.get_orgs()
errors = LDAPImportUtil().perform_import(users, orgs)
if errors:
return Response({'errors': errors}, status=400)
count = users if users is None else len(users)
orgs_name = ', '.join([str(org) for org in orgs])
return Response({
'msg': _('Imported {} users successfully (Organization: {})').format(count, org)
'msg': _('Imported {} users successfully (Organization: {})').format(count, orgs_name)
})