fix: 平台局部更新会自动关闭其他属性 (#10484)

Co-authored-by: feng <1304903146@qq.com>
pull/10494/head
fit2bot 2023-05-18 15:43:23 +08:00 committed by GitHub
parent 6c19fd4192
commit 44967b1af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 14 deletions

View File

@ -157,20 +157,6 @@ class PlatformSerializer(WritableNestedModelSerializer):
constraints = AllTypes.get_constraints(category, tp)
return constraints
def validate(self, attrs):
domain_enabled = attrs.get('domain_enabled', False) and self.constraints.get('domain_enabled', False)
su_enabled = attrs.get('su_enabled', False) and self.constraints.get('su_enabled', False)
automation = attrs.get('automation', {})
automation['ansible_enabled'] = automation.get('ansible_enabled', False) \
and self.constraints['automation'].get('ansible_enabled', False)
attrs.update({
'domain_enabled': domain_enabled,
'su_enabled': su_enabled,
'automation': automation,
})
self.initial_data['automation'] = automation
return attrs
@classmethod
def setup_eager_loading(cls, queryset):
queryset = queryset.prefetch_related(
@ -188,6 +174,18 @@ class PlatformSerializer(WritableNestedModelSerializer):
self.initial_data['protocols'] = protocols
return protocols
def validate_su_enabled(self, su_enabled):
return su_enabled and self.constraints.get('su_enabled', False)
def validate_domain_enabled(self, domain_enabled):
return domain_enabled and self.constraints.get('domain_enabled', False)
def validate_automation(self, automation):
automation = automation or {}
automation = automation.get('ansible_enabled', False) \
and self.constraints['automation'].get('ansible_enabled', False)
return automation
class PlatformOpsMethodSerializer(serializers.Serializer):
id = serializers.CharField(read_only=True)