mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-23 02:53:15 +00:00
Merge pull request #9366 from jumpserver/pr@dev@fix_no_db_name_mongodb_task_err
fix: mongodb无指定数据库时,一些自动化任务会失败
This commit is contained in:
commit
685b99e04d
@ -1,3 +1,6 @@
|
|||||||
|
from rest_framework.serializers import ValidationError
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from assets.models import Database
|
from assets.models import Database
|
||||||
from .common import AssetSerializer
|
from .common import AssetSerializer
|
||||||
from ..gateway import GatewayWithAccountSecretSerializer
|
from ..gateway import GatewayWithAccountSecretSerializer
|
||||||
@ -14,6 +17,13 @@ class DatabaseSerializer(AssetSerializer):
|
|||||||
]
|
]
|
||||||
fields = AssetSerializer.Meta.fields + extra_fields
|
fields = AssetSerializer.Meta.fields + extra_fields
|
||||||
|
|
||||||
|
def validate(self, attrs):
|
||||||
|
platform = attrs.get('platform')
|
||||||
|
if platform and getattr(platform, 'type') == 'mongodb' \
|
||||||
|
and not attrs.get('db_name'):
|
||||||
|
raise ValidationError({'db_name': _('This field is required.')})
|
||||||
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWithGatewaySerializer(DatabaseSerializer):
|
class DatabaseWithGatewaySerializer(DatabaseSerializer):
|
||||||
gateway = GatewayWithAccountSecretSerializer()
|
gateway = GatewayWithAccountSecretSerializer()
|
||||||
|
Loading…
Reference in New Issue
Block a user