mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-13 14:44:47 +00:00
perf: Add account date_expired
This commit is contained in:
parent
ae859c5562
commit
2acbb80920
@ -2,6 +2,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
from django.utils.timezone import get_current_timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
@ -60,15 +61,25 @@ class NodePermedSerializer(serializers.ModelSerializer):
|
|||||||
class AccountsPermedSerializer(serializers.ModelSerializer):
|
class AccountsPermedSerializer(serializers.ModelSerializer):
|
||||||
actions = ActionChoicesField(read_only=True)
|
actions = ActionChoicesField(read_only=True)
|
||||||
username = serializers.CharField(source='full_username', read_only=True)
|
username = serializers.CharField(source='full_username', read_only=True)
|
||||||
|
date_expired = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Account
|
model = Account
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'alias', 'name', 'username', 'has_username',
|
'id', 'alias', 'name', 'username', 'has_username',
|
||||||
'has_secret', 'secret_type', 'actions'
|
'has_secret', 'secret_type', 'actions', 'date_expired'
|
||||||
]
|
]
|
||||||
read_only_fields = fields
|
read_only_fields = fields
|
||||||
|
|
||||||
|
def get_date_expired(self, obj):
|
||||||
|
dt = obj.date_expired
|
||||||
|
if dt:
|
||||||
|
dt = dt.astimezone(get_current_timezone())
|
||||||
|
formatted = dt.strftime('%Y/%m/%d %H:%M:%S %z')
|
||||||
|
return formatted
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class AssetPermedDetailSerializer(AssetPermedSerializer):
|
class AssetPermedDetailSerializer(AssetPermedSerializer):
|
||||||
# 前面特意加了 permed,避免返回的是资产本身的
|
# 前面特意加了 permed,避免返回的是资产本身的
|
||||||
|
Loading…
Reference in New Issue
Block a user