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