perf: Push account record

pam
feng 2025-01-26 16:37:22 +08:00 committed by feng626
parent 3fca8eaead
commit 8fa189235e
4 changed files with 38 additions and 6 deletions

View File

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from rest_framework import mixins
from accounts import serializers from accounts import serializers
from accounts.const import AutomationTypes from accounts.const import AutomationTypes
from accounts.models import PushAccountAutomation from accounts.filters import PushAccountRecordFilterSet
from orgs.mixins.api import OrgBulkModelViewSet from accounts.models import PushAccountAutomation, PushSecretRecord
from orgs.mixins.api import OrgBulkModelViewSet, OrgGenericViewSet
from .base import ( from .base import (
AutomationAssetsListApi, AutomationRemoveAssetApi, AutomationAddAssetApi, AutomationAssetsListApi, AutomationRemoveAssetApi, AutomationAddAssetApi,
AutomationNodeAddRemoveApi, AutomationExecutionViewSet AutomationNodeAddRemoveApi, AutomationExecutionViewSet
@ -13,6 +15,7 @@ from .base import (
__all__ = [ __all__ = [
'PushAccountAutomationViewSet', 'PushAccountAssetsListApi', 'PushAccountRemoveAssetApi', 'PushAccountAutomationViewSet', 'PushAccountAssetsListApi', 'PushAccountRemoveAssetApi',
'PushAccountAddAssetApi', 'PushAccountNodeAddRemoveApi', 'PushAccountExecutionViewSet', 'PushAccountAddAssetApi', 'PushAccountNodeAddRemoveApi', 'PushAccountExecutionViewSet',
'PushAccountRecordViewSet'
] ]
@ -39,6 +42,22 @@ class PushAccountExecutionViewSet(AutomationExecutionViewSet):
return queryset return queryset
class PushAccountRecordViewSet(mixins.ListModelMixin, OrgGenericViewSet):
filterset_class = PushAccountRecordFilterSet
search_fields = ('asset__address', 'account_username')
ordering_fields = ('date_finished',)
tp = AutomationTypes.push_account
serializer_classes = {
'default': serializers.PushSecretRecordSerializer,
}
def get_queryset(self):
qs = PushSecretRecord.get_valid_records()
return qs.filter(
execution__automation__type=self.tp
)
class PushAccountAssetsListApi(AutomationAssetsListApi): class PushAccountAssetsListApi(AutomationAssetsListApi):
model = PushAccountAutomation model = PushAccountAutomation

View File

@ -7,7 +7,7 @@ from django_filters import rest_framework as drf_filters
from assets.models import Node from assets.models import Node
from common.drf.filters import BaseFilterSet from common.drf.filters import BaseFilterSet
from common.utils.timezone import local_zero_hour, local_now from common.utils.timezone import local_zero_hour, local_now
from .models import Account, GatheredAccount, ChangeSecretRecord from .models import Account, GatheredAccount, ChangeSecretRecord, PushSecretRecord
class AccountFilterSet(BaseFilterSet): class AccountFilterSet(BaseFilterSet):
@ -134,7 +134,7 @@ class GatheredAccountFilterSet(BaseFilterSet):
fields = ["id", "username"] fields = ["id", "username"]
class ChangeSecretRecordFilterSet(BaseFilterSet): class SecretRecordMixin:
asset_name = drf_filters.CharFilter( asset_name = drf_filters.CharFilter(
field_name="asset__name", lookup_expr="icontains" field_name="asset__name", lookup_expr="icontains"
) )
@ -155,6 +155,14 @@ class ChangeSecretRecordFilterSet(BaseFilterSet):
dt = local_now() - timezone.timedelta(days=value) dt = local_now() - timezone.timedelta(days=value)
return queryset.filter(date_finished__gte=dt) return queryset.filter(date_finished__gte=dt)
class ChangeSecretRecordFilterSet(SecretRecordMixin, BaseFilterSet):
class Meta: class Meta:
model = ChangeSecretRecord model = ChangeSecretRecord
fields = ["id", "status", "asset_id", "execution"] fields = ["id", "status", "asset_id", "execution"]
class PushAccountRecordFilterSet(SecretRecordMixin, BaseFilterSet):
class Meta:
model = PushSecretRecord
fields = ["id", "status", "asset_id", "execution"]

View File

@ -2,7 +2,7 @@ from accounts.const import AutomationTypes
from accounts.models import PushAccountAutomation from accounts.models import PushAccountAutomation
from .change_secret import ( from .change_secret import (
ChangeSecretAutomationSerializer, ChangeSecretUpdateAssetSerializer, ChangeSecretAutomationSerializer, ChangeSecretUpdateAssetSerializer,
ChangeSecretUpdateNodeSerializer ChangeSecretUpdateNodeSerializer, ChangeSecretRecordSerializer
) )
@ -19,6 +19,10 @@ class PushAccountAutomationSerializer(ChangeSecretAutomationSerializer):
return AutomationTypes.push_account return AutomationTypes.push_account
class PushSecretRecordSerializer(ChangeSecretRecordSerializer):
pass
class PushAccountUpdateAssetSerializer(ChangeSecretUpdateAssetSerializer): class PushAccountUpdateAssetSerializer(ChangeSecretUpdateAssetSerializer):
class Meta: class Meta:
model = PushAccountAutomation model = PushAccountAutomation

View File

@ -23,6 +23,7 @@ router.register(r'gather-account-automations', api.GatherAccountsAutomationViewS
router.register(r'gather-account-executions', api.GatherAccountsExecutionViewSet, 'gather-account-execution') router.register(r'gather-account-executions', api.GatherAccountsExecutionViewSet, 'gather-account-execution')
router.register(r'push-account-automations', api.PushAccountAutomationViewSet, 'push-account-automation') router.register(r'push-account-automations', api.PushAccountAutomationViewSet, 'push-account-automation')
router.register(r'push-account-executions', api.PushAccountExecutionViewSet, 'push-account-execution') router.register(r'push-account-executions', api.PushAccountExecutionViewSet, 'push-account-execution')
router.register(r'push-account-records', api.PushAccountRecordViewSet, 'push-account-record')
router.register(r'check-account-automations', api.CheckAccountAutomationViewSet, 'check-account-automation') router.register(r'check-account-automations', api.CheckAccountAutomationViewSet, 'check-account-automation')
router.register(r'check-account-executions', api.CheckAccountExecutionViewSet, 'check-account-execution') router.register(r'check-account-executions', api.CheckAccountExecutionViewSet, 'check-account-execution')
router.register(r'account-check-engines', api.CheckAccountEngineViewSet, 'account-check-engine') router.register(r'account-check-engines', api.CheckAccountEngineViewSet, 'account-check-engine')