fix: ldap test config msg error

pull/14130/head
wangruidong 2 months ago committed by Bryan
parent e319f20296
commit 4f9158b2ad

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

@ -117,12 +117,15 @@ class LdapWebsocket(AsyncJsonWebsocketConsumer):
data = json.loads(text_data) data = json.loads(text_data)
msg_type = data.pop('msg_type', 'testing_config') msg_type = data.pop('msg_type', 'testing_config')
try: try:
tool_func = getattr(self, f'run_{msg_type.lower()}') ok, msg = await asyncio.to_thread(self.run_func, f'run_{msg_type.lower()}', data)
ok, msg = await asyncio.to_thread(tool_func, data)
await self.send_msg(ok, msg) await self.send_msg(ok, msg)
except Exception as error: except Exception as error:
await self.send_msg(msg='Exception: %s' % 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=''): async def send_msg(self, ok=True, msg=''):
await self.send_json({'ok': ok, 'msg': f'{msg}'}) await self.send_json({'ok': ok, 'msg': f'{msg}'})
@ -186,11 +189,6 @@ class LdapWebsocket(AsyncJsonWebsocketConsumer):
return ok, msg return ok, msg
def run_import_user(self, data): 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 ok = False
org_ids = data.get('org_ids') org_ids = data.get('org_ids')
username_list = data.get('username_list', []) username_list = data.get('username_list', [])

Loading…
Cancel
Save