mirror of https://github.com/jumpserver/jumpserver
				
				
				
			fix: mongodb无指定数据库时,一些自动化任务会失败
							parent
							
								
									789695f90b
								
							
						
					
					
						commit
						c34b7e69eb
					
				| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
from rest_framework.serializers import ValidationError
 | 
			
		||||
from django.utils.translation import ugettext_lazy as _
 | 
			
		||||
 | 
			
		||||
from assets.models import Database
 | 
			
		||||
from .common import AssetSerializer
 | 
			
		||||
from ..gateway import GatewayWithAccountSecretSerializer
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +17,13 @@ class DatabaseSerializer(AssetSerializer):
 | 
			
		|||
        ]
 | 
			
		||||
        fields = AssetSerializer.Meta.fields + extra_fields
 | 
			
		||||
 | 
			
		||||
    def validate(self, attrs):
 | 
			
		||||
        platform = attrs.get('platform')
 | 
			
		||||
        if platform and getattr(platform, 'name') == 'MongoDB' \
 | 
			
		||||
                and not attrs.get('db_name'):
 | 
			
		||||
            raise ValidationError({'db_name': _('This field is required.')})
 | 
			
		||||
        return attrs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DatabaseWithGatewaySerializer(DatabaseSerializer):
 | 
			
		||||
    gateway = GatewayWithAccountSecretSerializer()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue