Browse Source

fix: 修复获取 swagger api 时,AssetSerializer category, type 字段手动设置 _choices 属性时报错的问题

pull/9404/head
Bai 2 years ago committed by Jiangjie.Bai
parent
commit
5fcd83b587
  1. 4
      apps/acls/serializers/login_acl.py
  2. 4
      apps/assets/serializers/asset/common.py
  3. 4
      apps/perms/serializers/permission.py
  4. 4
      apps/tickets/serializers/ticket/ticket.py

4
apps/acls/serializers/login_acl.py

@ -52,10 +52,10 @@ class LoginACLSerializer(BulkModelSerializer):
action = self.fields.get("action")
if not action:
return
choices = action._choices
choices = action.choices
if not has_valid_xpack_license():
choices.pop(LoginACL.ActionChoices.review, None)
action._choices = choices
action.choices = choices
def get_rules_serializer(self):
return RuleSerializer()

4
apps/assets/serializers/asset/common.py

@ -139,9 +139,9 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali
return
category = request.path.strip('/').split('/')[-1].rstrip('s')
field_category = self.fields.get('category')
field_category._choices = Category.filter_choices(category)
field_category.choices = Category.filter_choices(category)
field_type = self.fields.get('type')
field_type._choices = AllTypes.filter_choices(category)
field_type.choices = AllTypes.filter_choices(category)
@classmethod
def setup_eager_loading(cls, queryset):

4
apps/perms/serializers/permission.py

@ -70,9 +70,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer):
actions = self.fields.get("actions")
if not actions:
return
choices = actions._choices
actions._choices = choices
actions.default = list(choices.keys())
actions.default = list(actions.choices.keys())
@classmethod
def setup_eager_loading(cls, queryset):

4
apps/tickets/serializers/ticket/ticket.py

@ -39,9 +39,9 @@ class TicketSerializer(OrgResourceModelSerializerMixin):
tp = self.fields.get('type')
if not tp:
return
choices = tp._choices
choices = tp.choices
choices.pop(TicketType.general, None)
tp._choices = choices
tp.choices = choices
@classmethod
def setup_eager_loading(cls, queryset):

Loading…
Cancel
Save