jumpserver/apps/users/serializers/preference/luna.py

63 lines
2.2 KiB
Python

import json
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from users.const import RDPResolution, KeyboardLayout, RDPClientOption, AppletConnectionMethod
class MultipleChoiceField(serializers.MultipleChoiceField):
def to_representation(self, keys):
if isinstance(keys, str):
keys = json.loads(keys)
return keys
def to_internal_value(self, data):
data = super().to_internal_value(data)
return json.dumps(list(data))
class BasicSerializer(serializers.Serializer):
is_async_asset_tree = serializers.BooleanField(
required=False, default=True, label=_('Async loading of asset tree')
)
class GraphicsSerializer(serializers.Serializer):
rdp_resolution = serializers.ChoiceField(
RDPResolution.choices, default=RDPResolution.AUTO,
required=False, label=_('RDP resolution')
)
keyboard_layout = serializers.ChoiceField(
KeyboardLayout.choices, default=KeyboardLayout.EN_US_QWERTY,
required=False, label=_('Keyboard layout')
)
rdp_client_option = MultipleChoiceField(
choices=RDPClientOption.choices, default={RDPClientOption.FULL_SCREEN},
label=_('RDP client option'), required=False
)
applet_connection_method = serializers.ChoiceField(
AppletConnectionMethod.choices, default=AppletConnectionMethod.WEB,
required=False, label=_('Remote application connection method')
)
class CommandLineSerializer(serializers.Serializer):
character_terminal_font_size = serializers.IntegerField(
default=14, min_value=1, max_value=9999, required=False,
label=_('Character terminal font size'),
)
is_backspace_as_ctrl_h = serializers.BooleanField(
required=False, default=False, label=_('Backspace as Ctrl+H')
)
is_right_click_quickly_paste = serializers.BooleanField(
required=False, default=False, label=_('Right click quickly paste')
)
class LunaSerializer(serializers.Serializer):
basic = BasicSerializer(required=False, label=_('Basic'))
graphics = GraphicsSerializer(required=False, label=_('Graphics'))
command_line = CommandLineSerializer(required=False, label=_('Command line'))