perf: user setting (#11610)

Co-authored-by: feng <1304903146@qq.com>
pull/11611/head
fit2bot 2023-09-19 16:30:48 +08:00 committed by GitHub
parent f5c43488fd
commit b8fb23a0a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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)