From 50cbb75b96ef7d28b37e999b97413df64c24c399 Mon Sep 17 00:00:00 2001 From: Bai Date: Tue, 23 Apr 2024 12:00:14 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20Web=20=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E8=AF=A6=E6=83=85=E6=97=B6=E6=A0=B9=E6=8D=AE=20autofi?= =?UTF-8?q?ll=20=E7=B1=BB=E5=9E=8B=E8=BF=94=E5=9B=9E=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=20spec=5Finfo=20=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/serializers/asset/info/spec.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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,