From 12adf66f41031d5a73f1ce00cc85df4c2f2774d3 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 19 Apr 2023 10:37:46 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/api/account/account.py | 7 ++++++- ...gatheraccountsautomation_is_sync_account.py | 6 +++++- .../migrations/0011_account_source_id.py | 18 ------------------ apps/accounts/serializers/account/account.py | 1 + 4 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 apps/accounts/migrations/0011_account_source_id.py diff --git a/apps/accounts/api/account/account.py b/apps/accounts/api/account/account.py index 7b9991988..b25dafb9f 100644 --- a/apps/accounts/api/account/account.py +++ b/apps/accounts/api/account/account.py @@ -8,6 +8,7 @@ from accounts import serializers from accounts.filters import AccountFilterSet from accounts.models import Account from assets.models import Asset, Node +from common.api import ExtraFilterFieldsMixin from common.permissions import UserConfirmation, ConfirmType, IsValidUser from common.views.mixins import RecordViewLogMixin from orgs.mixins.api import OrgBulkModelViewSet @@ -111,7 +112,7 @@ class AssetAccountBulkCreateApi(CreateAPIView): return Response(data=serializer.data, status=HTTP_200_OK) -class AccountHistoriesSecretAPI(RecordViewLogMixin, ListAPIView): +class AccountHistoriesSecretAPI(ExtraFilterFieldsMixin, RecordViewLogMixin, ListAPIView): model = Account.history.model serializer_class = serializers.AccountHistorySerializer http_method_names = ['get', 'options'] @@ -123,6 +124,10 @@ class AccountHistoriesSecretAPI(RecordViewLogMixin, ListAPIView): def get_object(self): return get_object_or_404(Account, pk=self.kwargs.get('pk')) + @staticmethod + def filter_spm_queryset(resource_ids, queryset): + return queryset.filter(history_id__in=resource_ids) + def get_queryset(self): account = self.get_object() histories = account.history.all() diff --git a/apps/accounts/migrations/0010_gatheraccountsautomation_is_sync_account.py b/apps/accounts/migrations/0010_gatheraccountsautomation_is_sync_account.py index 058a7dd7e..259497692 100644 --- a/apps/accounts/migrations/0010_gatheraccountsautomation_is_sync_account.py +++ b/apps/accounts/migrations/0010_gatheraccountsautomation_is_sync_account.py @@ -4,7 +4,6 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ ('accounts', '0009_account_usernames_to_ids'), ] @@ -15,4 +14,9 @@ class Migration(migrations.Migration): name='is_sync_account', field=models.BooleanField(blank=True, default=False, verbose_name='Is sync account'), ), + migrations.AddField( + model_name='account', + name='source_id', + field=models.CharField(max_length=128, null=True, blank=True, verbose_name='Source ID'), + ), ] diff --git a/apps/accounts/migrations/0011_account_source_id.py b/apps/accounts/migrations/0011_account_source_id.py deleted file mode 100644 index ff9734404..000000000 --- a/apps/accounts/migrations/0011_account_source_id.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2.17 on 2023-03-23 07:08 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('accounts', '0010_gatheraccountsautomation_is_sync_account'), - ] - - operations = [ - migrations.AddField( - model_name='account', - name='source_id', - field=models.CharField(max_length=128, null=True, blank=True, verbose_name='Source ID'), - ), - ] diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index d79fd69e4..c76cb1788 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -392,6 +392,7 @@ class AccountSecretSerializer(SecretReadableMixin, AccountSerializer): class AccountHistorySerializer(serializers.ModelSerializer): secret_type = LabeledChoiceField(choices=SecretType.choices, label=_('Secret type')) + id = serializers.IntegerField(label=_('ID'), source='history_id', read_only=True) class Meta: model = Account.history.model