diff --git a/apps/assets/serializers/asset/info/spec.py b/apps/assets/serializers/asset/info/spec.py index 9a3dab960..a7aae17f4 100644 --- a/apps/assets/serializers/asset/info/spec.py +++ b/apps/assets/serializers/asset/info/spec.py @@ -22,6 +22,36 @@ class WebSpecSerializer(serializers.ModelSerializer): 'submit_selector', 'script' ] + def get_fields(self): + fields = super().get_fields() + if self.is_retrieve(): + # 查看 Web 资产详情时 + self.pop_fields_if_need(fields) + return fields + + def is_retrieve(self): + try: + self.context.get('request').method and self.parent.instance.web + return True + except Exception: + return False + + def pop_fields_if_need(self, fields): + fields_script = ['script'] + fields_basic = ['username_selector', 'password_selector', 'submit_selector'] + autofill = self.parent.instance.web.autofill + pop_fields_mapper = { + FillType.no: fields_script + fields_basic, + FillType.basic: fields_script, + FillType.script: fields_basic, + } + fields_pop = pop_fields_mapper.get(autofill, []) + for f in fields_pop: + fields.pop(f, None) + return fields + + + category_spec_serializer_map = { 'database': DatabaseSpecSerializer,