mirror of https://github.com/jumpserver/jumpserver
commit
0b1f6e2606
|
@ -74,5 +74,17 @@ class AccountHistoriesSecretAPI(RecordViewLogMixin, ListAPIView):
|
||||||
'list': 'accounts.view_accountsecret',
|
'list': 'accounts.view_accountsecret',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
return get_object_or_404(Account, pk=self.kwargs.get('pk'))
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.model.objects.filter(id=self.kwargs.get('pk'))
|
account = self.get_object()
|
||||||
|
histories = account.history.all()
|
||||||
|
last_history = account.history.first()
|
||||||
|
if not last_history:
|
||||||
|
return histories
|
||||||
|
|
||||||
|
if account.secret == last_history.secret \
|
||||||
|
and account.secret_type == last_history.secret_type:
|
||||||
|
histories = histories.exclude(history_id=last_history.history_id)
|
||||||
|
return histories
|
||||||
|
|
|
@ -90,6 +90,10 @@ class Account(AbsConnectivity, BaseAccount):
|
||||||
""" @INPUT 手动登录的账号(any) """
|
""" @INPUT 手动登录的账号(any) """
|
||||||
return cls(name=AliasAccount.INPUT.label, username=AliasAccount.INPUT.value, secret=None)
|
return cls(name=AliasAccount.INPUT.label, username=AliasAccount.INPUT.value, secret=None)
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
def versions(self):
|
||||||
|
return self.history.count()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_user_account(cls):
|
def get_user_account(cls):
|
||||||
""" @USER 动态用户的账号(self) """
|
""" @USER 动态用户的账号(self) """
|
||||||
|
|
|
@ -102,8 +102,8 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer):
|
||||||
class Meta(BaseAccountSerializer.Meta):
|
class Meta(BaseAccountSerializer.Meta):
|
||||||
model = Account
|
model = Account
|
||||||
fields = BaseAccountSerializer.Meta.fields + [
|
fields = BaseAccountSerializer.Meta.fields + [
|
||||||
'su_from', 'asset', 'template',
|
'su_from', 'asset', 'template', 'version',
|
||||||
'push_now', 'source', 'connectivity'
|
'push_now', 'source', 'connectivity',
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
**BaseAccountSerializer.Meta.extra_kwargs,
|
**BaseAccountSerializer.Meta.extra_kwargs,
|
||||||
|
@ -118,7 +118,8 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_eager_loading(cls, queryset):
|
def setup_eager_loading(cls, queryset):
|
||||||
""" Perform necessary eager loading of data. """
|
""" Perform necessary eager loading of data. """
|
||||||
queryset = queryset.prefetch_related('asset', 'asset__platform')
|
queryset = queryset \
|
||||||
|
.prefetch_related('asset', 'asset__platform')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
from django.db.models.signals import pre_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
|
from .models import Account
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=Account)
|
||||||
|
def on_account_pre_save(sender, instance, created=False, **kwargs):
|
||||||
|
if created:
|
||||||
|
instance.version = 1
|
||||||
|
else:
|
||||||
|
instance.version = instance.history.count()
|
||||||
|
|
|
@ -1954,7 +1954,7 @@ msgstr "清理审计会话任务日志"
|
||||||
|
|
||||||
#: authentication/api/confirm.py:40
|
#: authentication/api/confirm.py:40
|
||||||
msgid "This action require verify your MFA"
|
msgid "This action require verify your MFA"
|
||||||
msgstr "此操作需要验证您的 MFA"
|
msgstr "该操作需要验证您的 MFA, 请先开启并配置"
|
||||||
|
|
||||||
#: authentication/api/connection_token.py:268
|
#: authentication/api/connection_token.py:268
|
||||||
msgid "Account not found"
|
msgid "Account not found"
|
||||||
|
|
Loading…
Reference in New Issue