mirror of https://github.com/jumpserver/jumpserver
fix: 修复部分 password encrypted field extra kwargs 参数不生效问题
parent
25ae790f7d
commit
95f8b12912
|
@ -5,7 +5,6 @@ from assets.models import AuthBook
|
||||||
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||||
|
|
||||||
from .base import AuthSerializerMixin
|
from .base import AuthSerializerMixin
|
||||||
from .utils import validate_password_contains_left_double_curly_bracket
|
|
||||||
from common.utils.encode import ssh_pubkey_gen
|
from common.utils.encode import ssh_pubkey_gen
|
||||||
from common.drf.serializers import SecretReadableMixin
|
from common.drf.serializers import SecretReadableMixin
|
||||||
|
|
||||||
|
@ -32,10 +31,6 @@ class AccountSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
fields = fields_small + fields_fk
|
fields = fields_small + fields_fk
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'username': {'required': True},
|
'username': {'required': True},
|
||||||
'password': {
|
|
||||||
'write_only': True,
|
|
||||||
"validators": [validate_password_contains_left_double_curly_bracket]
|
|
||||||
},
|
|
||||||
'private_key': {'write_only': True},
|
'private_key': {'write_only': True},
|
||||||
'public_key': {'write_only': True},
|
'public_key': {'write_only': True},
|
||||||
'systemuser_display': {'label': _('System user display')}
|
'systemuser_display': {'label': _('System user display')}
|
||||||
|
|
|
@ -8,6 +8,7 @@ from rest_framework import serializers
|
||||||
from common.utils import ssh_pubkey_gen, ssh_private_key_gen, validate_ssh_private_key
|
from common.utils import ssh_pubkey_gen, ssh_private_key_gen, validate_ssh_private_key
|
||||||
from common.drf.fields import EncryptedField
|
from common.drf.fields import EncryptedField
|
||||||
from assets.models import Type
|
from assets.models import Type
|
||||||
|
from .utils import validate_password_contains_left_double_curly_bracket
|
||||||
|
|
||||||
|
|
||||||
class AuthSerializer(serializers.ModelSerializer):
|
class AuthSerializer(serializers.ModelSerializer):
|
||||||
|
@ -33,7 +34,8 @@ class AuthSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class AuthSerializerMixin(serializers.ModelSerializer):
|
class AuthSerializerMixin(serializers.ModelSerializer):
|
||||||
password = EncryptedField(
|
password = EncryptedField(
|
||||||
label=_('Password'), required=False, allow_blank=True, allow_null=True, max_length=1024
|
label=_('Password'), required=False, allow_blank=True, allow_null=True, max_length=1024,
|
||||||
|
validators=[validate_password_contains_left_double_curly_bracket]
|
||||||
)
|
)
|
||||||
private_key = EncryptedField(
|
private_key = EncryptedField(
|
||||||
label=_('SSH private key'), required=False, allow_blank=True, allow_null=True, max_length=4096
|
label=_('SSH private key'), required=False, allow_blank=True, allow_null=True, max_length=4096
|
||||||
|
|
|
@ -25,6 +25,11 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
"""
|
"""
|
||||||
系统用户
|
系统用户
|
||||||
"""
|
"""
|
||||||
|
password = EncryptedField(
|
||||||
|
label=_('Password'), required=False, allow_blank=True, allow_null=True, max_length=1024,
|
||||||
|
trim_whitespace=False, validators=[validate_password_contains_left_double_curly_bracket],
|
||||||
|
write_only=True
|
||||||
|
)
|
||||||
auto_generate_key = serializers.BooleanField(initial=True, required=False, write_only=True)
|
auto_generate_key = serializers.BooleanField(initial=True, required=False, write_only=True)
|
||||||
type_display = serializers.ReadOnlyField(source='get_type_display', label=_('Type display'))
|
type_display = serializers.ReadOnlyField(source='get_type_display', label=_('Type display'))
|
||||||
ssh_key_fingerprint = serializers.ReadOnlyField(label=_('SSH key fingerprint'))
|
ssh_key_fingerprint = serializers.ReadOnlyField(label=_('SSH key fingerprint'))
|
||||||
|
@ -51,15 +56,9 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
fields_m2m = ['cmd_filters', 'assets_amount', 'applications_amount', 'nodes']
|
fields_m2m = ['cmd_filters', 'assets_amount', 'applications_amount', 'nodes']
|
||||||
fields = fields_small + fields_m2m
|
fields = fields_small + fields_m2m
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'password': {
|
|
||||||
"write_only": True,
|
|
||||||
'trim_whitespace': False,
|
|
||||||
"validators": [validate_password_contains_left_double_curly_bracket]
|
|
||||||
},
|
|
||||||
'cmd_filters': {"required": False, 'label': _('Command filter')},
|
'cmd_filters': {"required": False, 'label': _('Command filter')},
|
||||||
'public_key': {"write_only": True},
|
'public_key': {"write_only": True},
|
||||||
'private_key': {"write_only": True},
|
'private_key': {"write_only": True},
|
||||||
'token': {"write_only": True},
|
|
||||||
'nodes_amount': {'label': _('Nodes amount')},
|
'nodes_amount': {'label': _('Nodes amount')},
|
||||||
'assets_amount': {'label': _('Assets amount')},
|
'assets_amount': {'label': _('Assets amount')},
|
||||||
'login_mode_display': {'label': _('Login mode display')},
|
'login_mode_display': {'label': _('Login mode display')},
|
||||||
|
|
Loading…
Reference in New Issue