mirror of https://github.com/jumpserver/jumpserver
parent
01827c7b3a
commit
06052b85a2
|
@ -57,11 +57,23 @@ class SerializeToTreeNodeMixin:
|
||||||
]
|
]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
def support_types(self):
|
||||||
|
from assets.const import AllTypes
|
||||||
|
return AllTypes.get_types_values(exclude_custom=True)
|
||||||
|
|
||||||
|
def get_icon(self, asset):
|
||||||
|
if asset.type in self.support_types:
|
||||||
|
return asset.type
|
||||||
|
else:
|
||||||
|
return 'file'
|
||||||
|
|
||||||
@timeit
|
@timeit
|
||||||
def serialize_assets(self, assets, node_key=None):
|
def serialize_assets(self, assets, node_key=None):
|
||||||
sftp_enabled_platform = PlatformProtocol.objects \
|
sftp_enabled_platform = PlatformProtocol.objects \
|
||||||
.filter(name='ssh', setting__sftp_enabled=True) \
|
.filter(name='ssh', setting__sftp_enabled=True) \
|
||||||
.values_list('platform', flat=True).distinct()
|
.values_list('platform', flat=True) \
|
||||||
|
.distinct()
|
||||||
if node_key is None:
|
if node_key is None:
|
||||||
get_pid = lambda asset: getattr(asset, 'parent_key', '')
|
get_pid = lambda asset: getattr(asset, 'parent_key', '')
|
||||||
else:
|
else:
|
||||||
|
@ -75,7 +87,7 @@ class SerializeToTreeNodeMixin:
|
||||||
'pId': get_pid(asset),
|
'pId': get_pid(asset),
|
||||||
'isParent': False,
|
'isParent': False,
|
||||||
'open': False,
|
'open': False,
|
||||||
'iconSkin': asset.type,
|
'iconSkin': self.get_icon(asset),
|
||||||
'chkDisabled': not asset.is_active,
|
'chkDisabled': not asset.is_active,
|
||||||
'meta': {
|
'meta': {
|
||||||
'type': 'asset',
|
'type': 'asset',
|
||||||
|
|
|
@ -151,15 +151,18 @@ class AllTypes(ChoicesMixin):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_types(cls):
|
def get_types(cls, exclude_custom=False):
|
||||||
choices = []
|
choices = []
|
||||||
for i in dict(cls.category_types()).values():
|
|
||||||
choices.extend(i.get_types())
|
for name, tp in dict(cls.category_types()).items():
|
||||||
|
if name == Category.CUSTOM and exclude_custom:
|
||||||
|
continue
|
||||||
|
choices.extend(tp.get_types())
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_types_values(cls):
|
def get_types_values(cls, exclude_custom=False):
|
||||||
choices = cls.get_types()
|
choices = cls.get_types(exclude_custom=exclude_custom)
|
||||||
return [c.value for c in choices]
|
return [c.value for c in choices]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from assets.const.web import FillType
|
from assets.const.web import FillType
|
||||||
from common.serializers import WritableNestedModelSerializer
|
from common.serializers import WritableNestedModelSerializer, type_field_map
|
||||||
from common.serializers.fields import LabeledChoiceField
|
from common.serializers.fields import LabeledChoiceField
|
||||||
from common.utils import lazyproperty
|
from common.utils import lazyproperty
|
||||||
from ..const import Category, AllTypes
|
from ..const import Category, AllTypes
|
||||||
|
@ -88,14 +88,7 @@ class PlatformProtocolSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class PlatformCustomField(serializers.Serializer):
|
class PlatformCustomField(serializers.Serializer):
|
||||||
TYPE_CHOICES = [
|
TYPE_CHOICES = [(t, t) for t, c in type_field_map.items()]
|
||||||
("str", "str"),
|
|
||||||
("text", "text"),
|
|
||||||
("int", "int"),
|
|
||||||
("bool", "bool"),
|
|
||||||
("choice", "choice"),
|
|
||||||
("list", "list"),
|
|
||||||
]
|
|
||||||
name = serializers.CharField(label=_("Name"), max_length=128)
|
name = serializers.CharField(label=_("Name"), max_length=128)
|
||||||
label = serializers.CharField(label=_("Label"), max_length=128)
|
label = serializers.CharField(label=_("Label"), max_length=128)
|
||||||
type = serializers.ChoiceField(choices=TYPE_CHOICES, label=_("Type"), default='str')
|
type = serializers.ChoiceField(choices=TYPE_CHOICES, label=_("Type"), default='str')
|
||||||
|
|
|
@ -7,6 +7,7 @@ example_info = [
|
||||||
|
|
||||||
type_field_map = {
|
type_field_map = {
|
||||||
"str": serializers.CharField,
|
"str": serializers.CharField,
|
||||||
|
"password": serializers.CharField,
|
||||||
"int": serializers.IntegerField,
|
"int": serializers.IntegerField,
|
||||||
"bool": serializers.BooleanField,
|
"bool": serializers.BooleanField,
|
||||||
"text": serializers.CharField,
|
"text": serializers.CharField,
|
||||||
|
@ -27,6 +28,8 @@ def set_default_if_need(data, i):
|
||||||
def set_default_by_type(tp, data, field_info):
|
def set_default_by_type(tp, data, field_info):
|
||||||
if tp == 'str':
|
if tp == 'str':
|
||||||
data['max_length'] = 4096
|
data['max_length'] = 4096
|
||||||
|
elif tp == 'password':
|
||||||
|
data['write_only'] = True
|
||||||
elif tp == 'choice':
|
elif tp == 'choice':
|
||||||
choices = field_info.pop('choices', [])
|
choices = field_info.pop('choices', [])
|
||||||
if isinstance(choices, str):
|
if isinstance(choices, str):
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:2dd0610d610c2660f35d50dc2871ac08cc09080d2503e1080a57d97c47fea471
|
oid sha256:591b458d6f8ea8d125bd584ca57768cd5aa5a7103b42e345eaadac744a73d475
|
||||||
size 114418
|
size 114412
|
||||||
|
|
|
@ -1060,7 +1060,7 @@ msgstr "Web"
|
||||||
|
|
||||||
#: assets/const/category.py:15
|
#: assets/const/category.py:15
|
||||||
msgid "Custom type"
|
msgid "Custom type"
|
||||||
msgstr "自定义类型"
|
msgstr "自定义"
|
||||||
|
|
||||||
#: assets/const/cloud.py:7
|
#: assets/const/cloud.py:7
|
||||||
msgid "Public cloud"
|
msgid "Public cloud"
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Applet(JMSBaseModel):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(d, 'platform.yml')) as f:
|
with open(os.path.join(d, 'platform.yml')) as f:
|
||||||
data = yaml.safe_load(f)
|
data = yaml_load_with_i18n(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValidationError({'error': _('Load platform.yml failed: {}').format(e)})
|
raise ValidationError({'error': _('Load platform.yml failed: {}').format(e)})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue