mirror of https://github.com/jumpserver/jumpserver
perf: 优化 Web 资产详情时根据 autofill 类型返回对应的 spec_info 信息
parent
d418647774
commit
50cbb75b96
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue