mirror of https://github.com/jumpserver/jumpserver
perf: add XPACKModelFieldsMixin
parent
5135186961
commit
7408ed0f03
|
@ -5,6 +5,7 @@ if sys.version_info.major >= 3 and sys.version_info.minor >= 10:
|
|||
from collections.abc import Iterable
|
||||
else:
|
||||
from collections import Iterable
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import NOT_PROVIDED
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -264,6 +265,14 @@ class SizedModelFieldsMixin(BaseDynamicFieldsPlugin):
|
|||
return fields_to_drop
|
||||
|
||||
|
||||
class XPACKModelFieldsMixin(BaseDynamicFieldsPlugin):
|
||||
def get_exclude_field_names(self):
|
||||
if settings.XPACK_LICENSE_IS_VALID:
|
||||
return set()
|
||||
fields_xpack = set(getattr(self.serializer.Meta, 'fields_xpack', set()))
|
||||
return fields_xpack
|
||||
|
||||
|
||||
class DefaultValueFieldsMixin:
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -302,7 +311,7 @@ class DynamicFieldsMixin:
|
|||
"""
|
||||
可以控制显示不同的字段,mini 最少,small 不包含关系
|
||||
"""
|
||||
dynamic_fields_plugins = [QueryFieldsMixin, SizedModelFieldsMixin]
|
||||
dynamic_fields_plugins = [QueryFieldsMixin, SizedModelFieldsMixin, XPACKModelFieldsMixin]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -124,11 +124,12 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, ResourceLa
|
|||
fields_write_only = [
|
||||
"password", "public_key",
|
||||
]
|
||||
# xpack 包含的字段
|
||||
fields_xpack = ["wecom_id", "dingtalk_id", "feishu_id", "lark_id", "slack_id"]
|
||||
# small 指的是 不需要计算的直接能从一张表中获取到的数据
|
||||
fields_small = fields_mini + fields_write_only + [
|
||||
"email", "wechat", "phone", "mfa_level", "source",
|
||||
"wecom_id", "dingtalk_id", "feishu_id", "lark_id",
|
||||
"slack_id", "created_by", "updated_by", "comment", # 通用字段
|
||||
*fields_xpack, "created_by", "updated_by", "comment", # 通用字段
|
||||
]
|
||||
fields_date = [
|
||||
"date_expired", "date_joined", "last_login",
|
||||
|
@ -157,8 +158,7 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, ResourceLa
|
|||
|
||||
read_only_fields = [
|
||||
"date_joined", "last_login", "created_by",
|
||||
"is_first_login", "wecom_id", "dingtalk_id",
|
||||
"feishu_id", "lark_id", "date_api_key_last_used",
|
||||
"is_first_login", *fields_xpack, "date_api_key_last_used",
|
||||
]
|
||||
fields_only_root_org = ["orgs_roles"]
|
||||
disallow_self_update_fields = ["is_active", "system_roles", "org_roles"]
|
||||
|
@ -182,10 +182,6 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, ResourceLa
|
|||
"is_otp_secret_key_bound": {"label": _("Is OTP bound")},
|
||||
'mfa_level': {'label': _("MFA level")},
|
||||
}
|
||||
if not settings.XPACK_LICENSE_IS_VALID:
|
||||
# 社区版去掉企业微信、钉钉、飞书、Lark、Slack
|
||||
fields = [f for f in fields if f not in ["wecom_id", "dingtalk_id",
|
||||
"feishu_id", "lark_id", "slack_id"]]
|
||||
|
||||
def get_fields(self):
|
||||
fields = super().get_fields()
|
||||
|
|
Loading…
Reference in New Issue