jumpserver/apps/assets/serializers/platform.py

46 lines
1.6 KiB
Python
Raw Normal View History

2022-04-26 13:30:01 +00:00
from rest_framework import serializers
from django.utils.translation import gettext_lazy as _
2022-08-18 09:58:59 +00:00
from common.drf.fields import ChoiceDisplayField
from common.drf.serializers import JMSWritableNestedModelSerializer
from ..models import Platform, PlatformProtocol
from ..const import Category, AllTypes
2022-04-26 13:30:01 +00:00
__all__ = ['PlatformSerializer']
2022-08-18 09:58:59 +00:00
class PlatformProtocolsSerializer(serializers.ModelSerializer):
class Meta:
model = PlatformProtocol
fields = ['id', 'name', 'port', 'setting']
2022-04-26 13:30:01 +00:00
2022-08-18 09:58:59 +00:00
class PlatformSerializer(JMSWritableNestedModelSerializer):
type = ChoiceDisplayField(choices=AllTypes.choices, label=_("Type"))
category = ChoiceDisplayField(choices=Category.choices, label=_("Category"))
protocols = PlatformProtocolsSerializer(label=_('Protocols'), many=True, required=False)
2022-08-10 11:27:08 +00:00
type_constraints = serializers.ReadOnlyField(required=False, read_only=True)
2022-04-26 13:30:01 +00:00
class Meta:
model = Platform
2022-04-30 15:19:43 +00:00
fields_mini = ['id', 'name', 'internal']
fields_small = fields_mini + [
2022-08-18 09:58:59 +00:00
'category', 'type',
]
fields = fields_small + [
'domain_enabled', 'domain_default',
2022-08-10 11:27:08 +00:00
'su_enabled', 'su_method',
2022-08-18 09:58:59 +00:00
'protocols_enabled', 'protocols',
2022-08-10 11:27:08 +00:00
'ping_enabled', 'ping_method',
'verify_account_enabled', 'verify_account_method',
'create_account_enabled', 'create_account_method',
'change_password_enabled', 'change_password_method',
'type_constraints',
2022-08-18 09:58:59 +00:00
'comment', 'charset',
2022-04-26 13:30:01 +00:00
]
2022-04-30 15:19:43 +00:00
read_only_fields = [
'category_display', 'type_display',
]