mirror of https://github.com/jumpserver/jumpserver
perf: Setting user attributes is invalid
parent
5d2d8ca487
commit
cea63e6083
|
@ -116,7 +116,6 @@ class DingTalkRequests(BaseRequest):
|
|||
|
||||
|
||||
class DingTalk:
|
||||
attributes = settings.DINGTALK_RENAME_ATTRIBUTES
|
||||
|
||||
def __init__(self, appid, appsecret, agentid, timeout=None):
|
||||
self._appid = appid or ''
|
||||
|
@ -128,6 +127,10 @@ class DingTalk:
|
|||
timeout=timeout
|
||||
)
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
return settings.DINGTALK_RENAME_ATTRIBUTES
|
||||
|
||||
def get_userinfo_bycode(self, code):
|
||||
body = {
|
||||
'clientId': self._appid,
|
||||
|
@ -210,8 +213,8 @@ class DingTalk:
|
|||
return data
|
||||
|
||||
@staticmethod
|
||||
def default_user_detail(data):
|
||||
username = data['user_id']
|
||||
def default_user_detail(data, user_id):
|
||||
username = data.get('userid', user_id)
|
||||
name = data.get('name', username)
|
||||
email = data.get('email') or data.get('org_email')
|
||||
email = construct_user_email(username, email)
|
||||
|
@ -227,6 +230,6 @@ class DingTalk:
|
|||
data = data['result']
|
||||
data['user_id'] = user_id
|
||||
info = flatten_dict(data)
|
||||
default_detail = self.default_user_detail(data)
|
||||
default_detail = self.default_user_detail(data, user_id)
|
||||
detail = map_attributes(default_detail, info, self.attributes)
|
||||
return detail
|
||||
|
|
|
@ -84,7 +84,6 @@ class FeiShu(RequestMixin):
|
|||
非业务数据导致的错误直接抛异常,说明是系统配置错误,业务代码不用理会
|
||||
"""
|
||||
requests_cls = FeishuRequests
|
||||
attributes = settings.FEISHU_RENAME_ATTRIBUTES
|
||||
|
||||
def __init__(self, app_id, app_secret, timeout=None):
|
||||
self._app_id = app_id or ''
|
||||
|
@ -97,6 +96,10 @@ class FeiShu(RequestMixin):
|
|||
)
|
||||
self.url_instance = self._requests.url_instance
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
return settings.FEISHU_RENAME_ATTRIBUTES
|
||||
|
||||
def get_user_id_by_code(self, code):
|
||||
# https://open.feishu.cn/document/ukTMukTMukTM/uEDO4UjLxgDO14SM4gTN
|
||||
|
||||
|
@ -138,8 +141,8 @@ class FeiShu(RequestMixin):
|
|||
return invalid_users
|
||||
|
||||
@staticmethod
|
||||
def default_user_detail(data):
|
||||
username = data['user_id']
|
||||
def default_user_detail(data, user_id):
|
||||
username = data.get('user_id', user_id)
|
||||
name = data.get('name', username)
|
||||
email = data.get('email') or data.get('enterprise_email')
|
||||
email = construct_user_email(username, email)
|
||||
|
@ -152,6 +155,6 @@ class FeiShu(RequestMixin):
|
|||
data = kwargs['other_info']
|
||||
data['user_id'] = user_id
|
||||
info = flatten_dict(data)
|
||||
default_detail = self.default_user_detail(data)
|
||||
default_detail = self.default_user_detail(data, user_id)
|
||||
detail = map_attributes(default_detail, info, self.attributes)
|
||||
return detail
|
||||
|
|
|
@ -16,4 +16,7 @@ class LarkRequests(FeishuRequests):
|
|||
|
||||
class Lark(FeiShu):
|
||||
requests_cls = LarkRequests
|
||||
attributes = settings.LARK_RENAME_ATTRIBUTES
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
return settings.LARK_RENAME_ATTRIBUTES
|
||||
|
|
|
@ -94,7 +94,6 @@ class SlackRequests:
|
|||
|
||||
|
||||
class Slack:
|
||||
attributes = settings.SLACK_RENAME_ATTRIBUTES
|
||||
|
||||
def __init__(self, client_id=None, client_secret=None, bot_token=None, **kwargs):
|
||||
self._client = SlackRequests(
|
||||
|
@ -102,6 +101,10 @@ class Slack:
|
|||
)
|
||||
self.markdown = mistune.Markdown(renderer=SlackRenderer())
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
return settings.SLACK_RENAME_ATTRIBUTES
|
||||
|
||||
def get_user_id_by_code(self, code):
|
||||
self._client.request_access_token(code)
|
||||
response = self._client.request(
|
||||
|
@ -141,8 +144,8 @@ class Slack:
|
|||
logger.exception(e)
|
||||
|
||||
@staticmethod
|
||||
def default_user_detail(data):
|
||||
username = data['user_id']
|
||||
def default_user_detail(data, user_id):
|
||||
username = data.get('id', user_id)
|
||||
username = data.get('name', username)
|
||||
name = data.get('real_name', username)
|
||||
email = data.get('profile.email')
|
||||
|
@ -157,6 +160,6 @@ class Slack:
|
|||
data = kwargs['other_info']
|
||||
data['user_id'] = user_id
|
||||
info = flatten_dict(data)
|
||||
default_detail = self.default_user_detail(data)
|
||||
default_detail = self.default_user_detail(data, user_id)
|
||||
detail = map_attributes(default_detail, info, self.attributes)
|
||||
return detail
|
||||
|
|
|
@ -80,7 +80,6 @@ class WeCom(RequestMixin):
|
|||
"""
|
||||
非业务数据导致的错误直接抛异常,说明是系统配置错误,业务代码不用理会
|
||||
"""
|
||||
attributes = settings.WECOM_RENAME_ATTRIBUTES
|
||||
|
||||
def __init__(self, corpid, corpsecret, agentid, timeout=None):
|
||||
self._corpid = corpid or ''
|
||||
|
@ -94,6 +93,10 @@ class WeCom(RequestMixin):
|
|||
timeout=timeout
|
||||
)
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
return settings.WECOM_RENAME_ATTRIBUTES
|
||||
|
||||
def send_markdown(self, users: Iterable, msg: AnyStr, **kwargs):
|
||||
pass
|
||||
|
||||
|
@ -176,8 +179,8 @@ class WeCom(RequestMixin):
|
|||
raise WeComError
|
||||
|
||||
@staticmethod
|
||||
def default_user_detail(data):
|
||||
username = data.get('userid')
|
||||
def default_user_detail(data, user_id):
|
||||
username = data.get('userid', user_id)
|
||||
name = data.get('name', username)
|
||||
email = data.get('email') or data.get('biz_mail')
|
||||
email = construct_user_email(username, email)
|
||||
|
@ -189,6 +192,6 @@ class WeCom(RequestMixin):
|
|||
# https://open.work.weixin.qq.com/api/doc/90000/90135/90196
|
||||
data = self._requests.get(URL.GET_USER_DETAIL, {'userid': user_id})
|
||||
info = flatten_dict(data)
|
||||
default_detail = self.default_user_detail(data)
|
||||
default_detail = self.default_user_detail(data, user_id)
|
||||
detail = map_attributes(default_detail, info, self.attributes)
|
||||
return detail
|
||||
|
|
|
@ -251,6 +251,12 @@ def flatten_dict(d, parent_key='', sep='.'):
|
|||
new_key = f"{parent_key}{sep}{k}" if parent_key else k
|
||||
if isinstance(v, dict):
|
||||
items.update(flatten_dict(v, new_key, sep=sep))
|
||||
elif isinstance(v, list):
|
||||
for i, item in enumerate(v):
|
||||
if isinstance(item, dict):
|
||||
items.update(flatten_dict(item, f"{new_key}[{i}]", sep=sep))
|
||||
else:
|
||||
items[f"{new_key}[{i}]"] = item
|
||||
else:
|
||||
items[new_key] = v
|
||||
return items
|
||||
|
|
Loading…
Reference in New Issue