From ec2b3b4cda72806b4a22550dfb82227eaeeff1d1 Mon Sep 17 00:00:00 2001 From: xinwen Date: Fri, 7 Aug 2020 13:53:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(user):=20=E8=B0=83=E6=95=B4`User`=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/models/user.py | 2 +- apps/users/serializers/user.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/users/models/user.py b/apps/users/models/user.py index 82791dbf5..6bda75b0a 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -161,7 +161,7 @@ class RoleMixin: role = ROLE.USER @property - def super_role_display(self): + def role_display(self): return self.get_role_display() @property diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index 4924aef17..65a8ee4ea 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -10,6 +10,7 @@ from common.mixins import CommonBulkSerializerMixin from common.serializers import AdaptedBulkListSerializer from common.permissions import CanUpdateDeleteUser from common.drf.fields import GroupConcatedPrimaryKeyRelatedField +from orgs.models import ROLE as ORG_ROLE from ..models import User, UserGroup @@ -50,9 +51,10 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): login_blocked = serializers.SerializerMethodField() can_update = serializers.SerializerMethodField() can_delete = serializers.SerializerMethodField() - org_role = serializers.CharField( + org_role = serializers.ChoiceField( label=_('Organization role name'), write_only=True, - allow_null=True, required=False, allow_blank=True + allow_null=True, required=False, allow_blank=True, + choices=ORG_ROLE.choices ) key_prefix_block = "_LOGIN_BLOCK_{}" @@ -64,7 +66,7 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): # small 指的是 不需要计算的直接能从一张表中获取到的数据 fields_small = fields_mini + [ 'password', 'email', 'public_key', 'wechat', 'phone', 'mfa_level', 'mfa_enabled', - 'mfa_level_display', 'mfa_force_enabled', 'super_role_display', + 'mfa_level_display', 'mfa_force_enabled', 'role_display', 'org_role_display', 'comment', 'source', 'is_valid', 'is_expired', 'is_active', 'created_by', 'is_first_login', 'password_strategy', 'date_password_last_updated', 'date_expired', @@ -87,8 +89,8 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): 'can_delete': {'read_only': True}, 'groups_display': {'label': _('Groups name')}, 'source_display': {'label': _('Source name')}, - 'role_display': {'label': _('Organization role name'), 'source': 'org_role_display'}, - 'super_role_display': {'label': _('Super role name')}, + 'org_role_display': {'label': _('Organization role name')}, + 'role_display': {'label': _('Super role name')}, } def __init__(self, *args, **kwargs):