mirror of https://github.com/jumpserver/jumpserver
perf: 优化操作日志一些内容
parent
791b175465
commit
6411642ced
|
@ -23,7 +23,7 @@ class ChromeSerializer(RemoteAppSerializer):
|
||||||
)
|
)
|
||||||
chrome_password = EncryptedField(
|
chrome_password = EncryptedField(
|
||||||
max_length=128, allow_blank=True, required=False,
|
max_length=128, allow_blank=True, required=False,
|
||||||
label=_('Chrome password'), allow_null=True
|
label=_('Chrome password'), allow_null=True, encrypted_key='chrome_password'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ MODELS_NEED_RECORD = (
|
||||||
'CommandFilter', 'Platform', 'Label',
|
'CommandFilter', 'Platform', 'Label',
|
||||||
# applications
|
# applications
|
||||||
'Application',
|
'Application',
|
||||||
|
# account
|
||||||
|
'AuthBook',
|
||||||
# orgs
|
# orgs
|
||||||
'Organization',
|
'Organization',
|
||||||
# settings
|
# settings
|
||||||
|
|
|
@ -59,14 +59,15 @@ def get_resource_display(resource):
|
||||||
def model_to_dict_for_operate_log(
|
def model_to_dict_for_operate_log(
|
||||||
instance, include_model_fields=True, include_related_fields=True
|
instance, include_model_fields=True, include_related_fields=True
|
||||||
):
|
):
|
||||||
need_continue_fields = ['date_updated']
|
model_need_continue_fields = ['date_updated']
|
||||||
|
m2m_need_continue_fields = ['history_passwords']
|
||||||
opts = instance._meta
|
opts = instance._meta
|
||||||
data = {}
|
data = {}
|
||||||
for f in chain(opts.concrete_fields, opts.private_fields):
|
for f in chain(opts.concrete_fields, opts.private_fields):
|
||||||
if isinstance(f, (models.FileField, models.ImageField)):
|
if isinstance(f, (models.FileField, models.ImageField)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if getattr(f, 'attname', None) in need_continue_fields:
|
if getattr(f, 'attname', None) in model_need_continue_fields:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
value = getattr(instance, f.name) or getattr(instance, f.attname)
|
value = getattr(instance, f.name) or getattr(instance, f.attname)
|
||||||
|
@ -75,11 +76,6 @@ def model_to_dict_for_operate_log(
|
||||||
|
|
||||||
if getattr(f, 'primary_key', False):
|
if getattr(f, 'primary_key', False):
|
||||||
f.verbose_name = 'id'
|
f.verbose_name = 'id'
|
||||||
elif isinstance(f, (
|
|
||||||
fields.EncryptCharField, fields.EncryptTextField,
|
|
||||||
fields.EncryptJsonDictCharField, fields.EncryptJsonDictTextField
|
|
||||||
)) or getattr(f, 'attname', '') == 'password':
|
|
||||||
value = 'encrypt|%s' % value
|
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
value = [str(v) for v in value]
|
value = [str(v) for v in value]
|
||||||
|
|
||||||
|
@ -91,11 +87,12 @@ def model_to_dict_for_operate_log(
|
||||||
value = []
|
value = []
|
||||||
if instance.pk is not None:
|
if instance.pk is not None:
|
||||||
related_name = getattr(f, 'attname', '') or getattr(f, 'related_name', '')
|
related_name = getattr(f, 'attname', '') or getattr(f, 'related_name', '')
|
||||||
if related_name:
|
if not related_name or related_name in m2m_need_continue_fields:
|
||||||
try:
|
continue
|
||||||
value = [str(i) for i in getattr(instance, related_name).all()]
|
try:
|
||||||
except:
|
value = [str(i) for i in getattr(instance, related_name).all()]
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -32,8 +32,9 @@ class EncryptedField(serializers.CharField):
|
||||||
if write_only is None:
|
if write_only is None:
|
||||||
write_only = True
|
write_only = True
|
||||||
kwargs['write_only'] = write_only
|
kwargs['write_only'] = write_only
|
||||||
|
encrypted_key = kwargs.pop('encrypted_key', None)
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
add_encrypted_field_set(self.label)
|
add_encrypted_field_set(encrypted_key or self.label)
|
||||||
|
|
||||||
def to_internal_value(self, value):
|
def to_internal_value(self, value):
|
||||||
value = super().to_internal_value(value)
|
value = super().to_internal_value(value)
|
||||||
|
|
Loading…
Reference in New Issue