perf: update user serializer

pull/14989/head
ibuler 2025-03-10 15:24:41 +08:00
parent 56d0a6d0b0
commit f46cc0f040
3 changed files with 34 additions and 56 deletions

View File

@ -310,7 +310,7 @@
"CloudCreate": "Create asset - cloud",
"CloudRegionTip": "The region was not obtained, please check the account",
"CloudSource": "Sync source",
"CloudSync": "Cloud provider",
"CloudSync": "Cloud sync",
"CloudSyncConfig": "Cloud sync settings",
"CloudUpdate": "Update the asset - cloud",
"Cluster": "Cluster",
@ -1095,7 +1095,7 @@
"Rule": "Condition",
"RuleCount": "Condition quantity",
"RuleDetail": "Rule details",
"RuleRelation": "Relationship conditions",
"RuleRelation": "Rule relation",
"RuleRelationHelpTip": "And: the action will be executed only when all conditions are met; or: the action will be executed as long as one condition is met",
"RuleSetting": "Condition settings",
"Rules": "Rules",
@ -1360,8 +1360,8 @@
"TotalJobFailed": "Failed execution actions",
"TotalJobLog": "Total job executions",
"TotalJobRunning": "Running jobs",
"TotalSyncAsset": "Assets",
"TotalSyncRegion": "Regions",
"TotalSyncAsset": "Synced Assets",
"TotalSyncRegion": "Sync Regions",
"TotalSyncStrategy": "Number of strategies",
"Transfer": "Transfer",
"TriggerMode": "Trigger mode",

View File

@ -1,14 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import base64
import struct
import uuid
import math
from django.conf import settings
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager
from django.core.exceptions import ValidationError
from django.db import models
from django.shortcuts import reverse
from django.utils import timezone
@ -17,17 +13,16 @@ from rest_framework.exceptions import PermissionDenied
from common.db import fields, models as jms_models
from common.utils import (
date_expired_default,
get_logger,
date_expired_default, get_logger, lazyproperty
)
from labels.mixins import LabeledMixin
from orgs.utils import current_org
from ._auth import AuthMixin, MFAMixin
from ._face import FaceMixin
from ._json import JSONFilterMixin
from ._role import RoleMixin, SystemRoleManager, OrgRoleManager
from ._source import SourceMixin, Source
from ._token import TokenMixin
from ._face import FaceMixin
logger = get_logger(__file__)
__all__ = [
@ -272,7 +267,7 @@ class User(
LoginBlockUtil.unblock_user(self.username)
MFABlockUtils.unblock_user(self.username)
@property
@lazyproperty
def login_blocked(self):
from users.utils import LoginBlockUtil, MFABlockUtils

View File

@ -168,60 +168,43 @@ class UserSerializer(
# mini 是指能识别对象的最小单元
fields_mini = ["id", "name", "username"]
# 只能写的字段, 这个虽然无法在框架上生效,但是更多对我们是提醒
fields_write_only = [
"password",
"public_key",
]
fields_write_only = ["password", "public_key", ]
# xpack 包含的字段
fields_xpack = ["wecom_id", "dingtalk_id", "feishu_id", "lark_id", "slack_id", "is_org_admin", "orgs_roles",
"org_roles"]
fields_xpack = [
"wecom_id", "dingtalk_id", "feishu_id", "lark_id", "slack_id",
"is_org_admin", "orgs_roles", "org_roles"
]
# small 指的是 不需要计算的直接能从一张表中获取到的数据
fields_small = (
fields_mini
+ fields_write_only
+ [
"email",
"wechat",
"phone",
"mfa_level",
"source",
*fields_xpack,
"created_by",
"updated_by",
"comment", # 通用字段
]
fields_mini
+ fields_write_only
+ [
"email", "wechat", "phone", "mfa_level",
"source", *fields_xpack,
"created_by", "updated_by", "comment", # 通用字段
]
)
fields_date = [
"date_expired",
"date_joined",
"last_login",
"date_updated",
"date_api_key_last_used",
"date_expired", "date_joined", "last_login",
"date_updated", "date_api_key_last_used",
]
fields_bool = [
"is_superuser",
"is_org_admin",
"is_service_account",
"is_valid",
"is_expired",
"is_active", # 布尔字段
"is_otp_secret_key_bound",
"can_public_key_auth",
"mfa_enabled",
"need_update_password",
"is_face_code_set",
"is_superuser", "is_org_admin", "is_service_account",
"is_valid", "is_expired", "is_active", # 布尔字段
"is_otp_secret_key_bound", "can_public_key_auth",
"mfa_enabled", "need_update_password", "is_face_code_set",
]
# 包含不太常用的字段,可以没有
fields_verbose = (
fields_small
+ fields_date
+ fields_bool
+ [
"mfa_force_enabled",
"is_first_login",
"date_password_last_updated",
"avatar_url",
]
fields_small
+ fields_date
+ fields_bool
+ [
"mfa_force_enabled",
"is_first_login",
"date_password_last_updated",
"avatar_url",
]
)
# 外键的字段
fields_fk = []