fix: 修改用户自更新失败的问题

pull/8647/head v2.23.4
Jiangjie.Bai 2022-07-12 14:09:08 +08:00 committed by 老广
parent 9cfbbe9157
commit 8aa21db52b
1 changed files with 7 additions and 3 deletions

View File

@ -6,7 +6,7 @@ from rest_framework import serializers
from common.mixins import CommonBulkSerializerMixin
from common.validators import PhoneValidator
from common.utils import pretty_string
from common.utils import pretty_string, get_logger
from common.drf.fields import EncryptedField
from rbac.builtin import BuiltinRole
from rbac.permissions import RBACPermission
@ -19,6 +19,8 @@ __all__ = [
'InviteSerializer', 'ServiceAccountSerializer',
]
logger = get_logger(__file__)
class RolesSerializerMixin(serializers.Serializer):
system_roles = serializers.ManyRelatedField(
@ -198,8 +200,10 @@ class UserSerializer(RolesSerializerMixin, CommonBulkSerializerMixin, serializer
if not disallow_fields:
return attrs
# 用户自己不能更新自己的一些字段
error = _('User cannot self-update fields: {}').format(disallow_fields)
raise serializers.ValidationError(error)
logger.debug('Disallow update self fields: %s', disallow_fields)
for field in disallow_fields:
attrs.pop(field, None)
return attrs
def validate(self, attrs):
attrs = self.check_disallow_self_update_fields(attrs)