From 8f8935ddd89e247fc842e056edd95fdc1099b842 Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Tue, 24 Dec 2024 18:31:41 +0800 Subject: [PATCH] perf: Update status action to handle multiple accounts --- apps/accounts/api/automations/gather_account.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/accounts/api/automations/gather_account.py b/apps/accounts/api/automations/gather_account.py index fe20f72c1..b7d10edf6 100644 --- a/apps/accounts/api/automations/gather_account.py +++ b/apps/accounts/api/automations/gather_account.py @@ -81,19 +81,18 @@ class GatheredAccountViewSet(OrgBulkModelViewSet): "details": serializers.GatheredAccountDetailsSerializer } rbac_perms = { - "sync_accounts": "assets.add_gatheredaccount", "status": "assets.change_gatheredaccount", "details": "assets.view_gatheredaccount" } - @action(methods=["put"], detail=True, url_path="status") + @action(methods=["put"], detail=False, url_path="status") def status(self, request, *args, **kwargs): - instance = self.get_object() - instance.status = request.data.get("status") - instance.save(update_fields=["status"]) - - if instance.status == "confirmed": - GatheredAccount.sync_accounts([instance]) + ids = request.data.get('ids', []) + new_status = request.data.get("status") + updated_instances = GatheredAccount.objects.filter(id__in=ids) + updated_instances.update(status=new_status) + if new_status == "confirmed": + GatheredAccount.sync_accounts(updated_instances) return Response(status=status.HTTP_200_OK)