[Update] 更新系统用户认证信息private_key转换

pull/3603/head
Bai 2020-01-07 15:53:53 +08:00
parent f88cb3da20
commit 005272cdc0
2 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
#
import io
import os
import uuid
from hashlib import md5
@ -76,6 +77,14 @@ class AssetUser(OrgModelMixin):
i = '-'.join(str(self.id).split('-')[:3])
return i
def get_private_key(self):
if not self.private_key_obj:
return None
string_io = io.StringIO()
self.private_key_obj.write_private_key(string_io)
private_key = string_io.getvalue()
return private_key
def get_related_assets(self):
assets = self.assets.all()
return assets

View File

@ -123,6 +123,7 @@ class SystemUserAuthSerializer(AuthSerializer):
"""
系统用户认证信息
"""
private_key = serializers.SerializerMethodField()
class Meta:
model = SystemUser
@ -131,6 +132,10 @@ class SystemUserAuthSerializer(AuthSerializer):
"login_mode", "password", "private_key",
]
@staticmethod
def get_private_key(obj):
return obj.get_private_key()
class SystemUserSimpleSerializer(serializers.ModelSerializer):
"""