mirror of https://github.com/jumpserver/jumpserver
parent
f5c43488fd
commit
b8fb23a0a0
|
@ -2,9 +2,11 @@ from django.utils.translation import gettext_lazy as _
|
|||
from rest_framework import serializers
|
||||
|
||||
from common.serializers.fields import EncryptedField
|
||||
from ...models import Preference
|
||||
|
||||
|
||||
class BasicSerializer(serializers.Serializer):
|
||||
has_secret_key = serializers.SerializerMethodField()
|
||||
secret_key = EncryptedField(
|
||||
required=False, max_length=1024,
|
||||
write_only=True, allow_blank=True,
|
||||
|
@ -16,6 +18,11 @@ class BasicSerializer(serializers.Serializer):
|
|||
label=_('Confirm file encryption password')
|
||||
)
|
||||
|
||||
def get_has_secret_key(self, obj):
|
||||
user = self.context['request'].user
|
||||
query = {'user': user, 'name': 'secret_key', 'category': 'lina'}
|
||||
return Preference.objects.filter(**query).exists()
|
||||
|
||||
def validate(self, attrs):
|
||||
secret_key = attrs.pop('secret_key', None)
|
||||
secret_key_again = attrs.pop('secret_key_again', None)
|
||||
|
|
Loading…
Reference in New Issue