Repository: TencentBlueKing/bk-user

Issue:
页面中同一个用户左侧搜索，以及组织内搜索展示数据不一致
**用文字描述你遇到的问题**

页面中同一个用户左侧搜索，以及组织内搜索展示数据不一致

**重现方法**

新建不同的动态用户字段，测试用户补充新字段内容。
左侧搜索测试用户
<img width="926" alt="企业微信截图_16749828179039" src="https://user-images.githubusercontent.com/49228807/215369087-044f5ac8-c0bb-4e99-8689-e13d62f06522.png">

组织内搜索测试用户
<img width="792" alt="企业微信截图_1674982885309" src="https://user-images.githubusercontent.com/49228807/215369093-206441f7-9d26-488f-b54c-d817720d7dec.png">


**预期行为**

两种搜索数据应该一致

**版本**
- v2.5.2/v2.5.1

**如果是 SaaS 页面问题，请提供使用的操作系统和浏览器信息**
 - OS: [e.g. iOS]
 - Browser [e.g. chrome, safari]
 - Version [e.g. 22]

**额外信息**

任何你觉得有助于问题解决的内容



Discussion:
规划放 2.5.3
两个搜索接口返回的数据格式不一致，我调整一下交互逻辑
api/v1/web/profiles/search/ 这个接口缺少 account_expiration_date 字段，搜索结果也不一致
我一会看下, 加上这个字段

Resolving patch:
diff --git a/src/api/bkuser_core/api/web/profile/serializers.py b/src/api/bkuser_core/api/web/profile/serializers.py
--- a/src/api/bkuser_core/api/web/profile/serializers.py
+++ b/src/api/bkuser_core/api/web/profile/serializers.py
@@ -8,12 +8,19 @@
 an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 specific language governing permissions and limitations under the License.
 """
+from typing import Dict
 
 from django.conf import settings
 from rest_framework import serializers
 
 from bkuser_core.api.web.serializers import StringArrayField
-from bkuser_core.api.web.utils import escape_value, get_default_category_id, get_raw_password
+from bkuser_core.api.web.utils import (
+    escape_value,
+    expand_extra_fields,
+    get_default_category_id,
+    get_extras_with_default_values,
+    get_raw_password,
+)
 from bkuser_core.profiles.models import Profile
 from bkuser_core.profiles.validators import validate_username
 
@@ -78,18 +85,19 @@ class ProfileSearchOutputSLZ(serializers.Serializer):
     # A: 需要, 搜索结果点击后直接渲染表单进行展示/更新
     id = serializers.CharField(required=False, help_text="用户ID")
     username = serializers.CharField(required=False, help_text="用户名")
+    display_name = serializers.CharField(required=False, help_text="中文名")
+
     qq = serializers.CharField(required=False, help_text="QQ")
     email = serializers.CharField(required=False, help_text="邮箱")
     telephone = serializers.CharField(required=False, help_text="电话")
     wx_userid = serializers.CharField(required=False, help_text="微信用户id")
     domain = serializers.CharField(required=False, help_text="域")
-    display_name = serializers.CharField(required=False, help_text="中文名")
     status = serializers.CharField(required=False, help_text="账户状态")
     staff_status = serializers.CharField(required=False, help_text="在职状态")
     position = serializers.CharField(required=False, help_text="职位")
     enabled = serializers.BooleanField(required=False, help_text="是否启用", default=True)
-    extras = serializers.JSONField(required=False, help_text="扩展字段")
     password_valid_days = serializers.IntegerField(required=False, help_text="密码有效期")
+    account_expiration_date = serializers.CharField(required=False)
     country_code = serializers.CharField(required=False, help_text="国家码")
     iso_code = serializers.CharField(required=False, help_text="国家码")
     time_zone = serializers.CharField(required=False, help_text="时区")
@@ -101,6 +109,17 @@ class ProfileSearchOutputSLZ(serializers.Serializer):
     departments = ProfileSearchResultDepartmentSerializer(many=True, required=False, help_text="部门列表")
     leaders = ProfileSearchResultLeaderSerializer(many=True, required=False, help_text="上级列表", source="leader")
 
+    # extras = serializers.JSONField(required=False, help_text="扩展字段")
+    extras = serializers.SerializerMethodField(required=False, read_only=True)
+
+    def get_extras(self, obj: "Profile") -> Dict:
+        """尝试从 context 中获取默认字段值"""
+        return get_extras_with_default_values(obj.extras)
+
+    def to_representation(self, instance):
+        data = super().to_representation(instance)
+        return expand_extra_fields(data)
+
 
 class ProfileUpdateInputSLZ(serializers.ModelSerializer):
     leader = serializers.ListField(child=serializers.IntegerField(), required=False)
diff --git a/src/api/bkuser_core/api/web/search/serializers.py b/src/api/bkuser_core/api/web/search/serializers.py
--- a/src/api/bkuser_core/api/web/search/serializers.py
+++ b/src/api/bkuser_core/api/web/search/serializers.py
@@ -66,6 +66,7 @@ class SearchResultProfileOutputSLZ(serializers.Serializer):
     country_code = serializers.CharField(required=False, help_text="国家码")
     iso_code = serializers.CharField(required=False, help_text="国家码")
     time_zone = serializers.CharField(required=False, help_text="时区")
+
     last_login_time = serializers.DateTimeField(required=False, help_text="最后登录时间")
     create_time = serializers.DateTimeField(required=False, help_text="创建时间")
     update_time = serializers.DateTimeField(required=False, help_text="更新时间")
diff --git a/src/api/bkuser_core/api/web/setting/views.py b/src/api/bkuser_core/api/web/setting/views.py
--- a/src/api/bkuser_core/api/web/setting/views.py
+++ b/src/api/bkuser_core/api/web/setting/views.py
@@ -12,11 +12,11 @@
 from rest_framework import generics
 
 from .serializers import SettingMetaOutputSLZ, SettingMetasListInputSLZ
-
-# from bkuser_core.bkiam.permissions import ManageFieldPermission
 from bkuser_core.api.web.constants import EXCLUDE_SETTINGS_META_IN_META_LISTVIEW
 from bkuser_core.user_settings.models import SettingMeta
 
+# from bkuser_core.bkiam.permissions import ManageFieldPermission
+
 
 class SettingMetasListApi(generics.ListAPIView):
     # NOTE: 后台没有任何权限管控(这个是全局的, 不关联任何目录/资源), 这里暂时使用 MANAGE_FIELD 权限替代, FIXME: 切分独立权限, 替换这里


Test patch: