From 4f9158b2adcb97b7ac07fdb51528d2f4beabb1c9 Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Thu, 12 Sep 2024 10:31:02 +0800 Subject: [PATCH] fix: ldap test config msg error --- apps/settings/utils/ldap.py | 2 +- apps/settings/ws.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/settings/utils/ldap.py b/apps/settings/utils/ldap.py index ca0a4f75a..e896c190e 100644 --- a/apps/settings/utils/ldap.py +++ b/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) diff --git a/apps/settings/ws.py b/apps/settings/ws.py index 586a7d4e4..6dca2f0a2 100644 --- a/apps/settings/ws.py +++ b/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', [])