Browse Source

fix: ldap test config msg error

pull/14130/head
wangruidong 2 months ago committed by Bryan
parent
commit
4f9158b2ad
  1. 2
      apps/settings/utils/ldap.py
  2. 12
      apps/settings/ws.py

2
apps/settings/utils/ldap.py

@ -78,7 +78,7 @@ class LDAPConfig(object):
self.bind_dn = getattr(settings, f"{prefix}_BIND_DN")
self.password = getattr(settings, f"{prefix}_BIND_PASSWORD")
self.use_ssl = getattr(settings, f"{prefix}_START_TLS")
self.search_ou = getattr(settings, f"{prefix})_SEARCH_OU")
self.search_ou = getattr(settings, f"{prefix}_SEARCH_OU")
self.search_filter = getattr(settings, f"{prefix}_SEARCH_FILTER")
self.attr_map = getattr(settings, f"{prefix}_USER_ATTR_MAP")
self.auth_ldap = getattr(settings, prefix)

12
apps/settings/ws.py

@ -117,12 +117,15 @@ class LdapWebsocket(AsyncJsonWebsocketConsumer):
data = json.loads(text_data)
msg_type = data.pop('msg_type', 'testing_config')
try:
tool_func = getattr(self, f'run_{msg_type.lower()}')
ok, msg = await asyncio.to_thread(tool_func, data)
ok, msg = await asyncio.to_thread(self.run_func, f'run_{msg_type.lower()}', data)
await self.send_msg(ok, msg)
except Exception as error:
await self.send_msg(msg='Exception: %s' % error)
def run_func(self, func_name, data):
with translation.override(getattr(self.scope['user'], 'lang', settings.LANGUAGE_CODE)):
return getattr(self, func_name)(data)
async def send_msg(self, ok=True, msg=''):
await self.send_json({'ok': ok, 'msg': f'{msg}'})
@ -186,11 +189,6 @@ class LdapWebsocket(AsyncJsonWebsocketConsumer):
return ok, msg
def run_import_user(self, data):
lang = getattr(self.scope['user'], 'lang', settings.LANGUAGE_CODE)
with translation.override(lang):
return self._run_import_user(data)
def _run_import_user(self, data):
ok = False
org_ids = data.get('org_ids')
username_list = data.get('username_list', [])

Loading…
Cancel
Save