From b8c872c68e1e25759f3784170d6fbb2a5dcd640f Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:53:45 +0800 Subject: [PATCH] perf: account cannot be modified (#9585) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/api/automations/base.py | 6 +++--- apps/accounts/serializers/account/account.py | 2 ++ apps/jumpserver/api.py | 9 --------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/apps/accounts/api/automations/base.py b/apps/accounts/api/automations/base.py index 12fcd7b17..700484e9b 100644 --- a/apps/accounts/api/automations/base.py +++ b/apps/accounts/api/automations/base.py @@ -3,10 +3,10 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import status, mixins, viewsets from rest_framework.response import Response +from accounts.models import AutomationExecution +from accounts.tasks import execute_automation from assets import serializers from assets.models import BaseAutomation -from accounts.tasks import execute_automation -from accounts.models import AutomationExecution from common.const.choices import Trigger from orgs.mixins import generics @@ -110,6 +110,6 @@ class AutomationExecutionViewSet( serializer.is_valid(raise_exception=True) automation = serializer.validated_data.get('automation') task = execute_automation.delay( - pid=automation.pk, trigger=Trigger.manual, tp=self.tp + pid=str(automation.pk), trigger=Trigger.manual, tp=self.tp ) return Response({'task': task.id}, status=status.HTTP_201_CREATED) diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index 3db4cf445..e2d2f358d 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -52,6 +52,8 @@ class AccountSerializerCreateValidateMixin: return instance def update(self, instance, validated_data): + # account cannot be modified + validated_data.pop('username', None) push_now = validated_data.pop('push_now', None) instance = super().update(instance, validated_data) self.push_account(instance, push_now) diff --git a/apps/jumpserver/api.py b/apps/jumpserver/api.py index 6a3617c0c..f3fee7c1d 100644 --- a/apps/jumpserver/api.py +++ b/apps/jumpserver/api.py @@ -295,10 +295,6 @@ class DatesLoginMetricMixin: def user_login_success_logs_amount(self): return self.login_logs_queryset.filter(status=LoginStatusChoices.success).count() - @lazyproperty - def user_login_logs_amount(self): - return self.login_logs_queryset.values('username').count() - @lazyproperty def user_login_amount(self): return self.login_logs_queryset.values('username').distinct().count() @@ -383,11 +379,6 @@ class IndexApi(DateTimeMixin, DatesLoginMetricMixin, APIView): 'total_count_login_users': self.user_login_amount }) - if _all or query_params.get('total_count') or query_params.get('total_count_login_user_logs'): - data.update({ - 'total_count_login_user_logs': self.user_login_logs_amount - }) - if _all or query_params.get('total_count') or query_params.get('total_count_today_active_assets'): data.update({ 'total_count_today_active_assets': caches.total_count_today_active_assets,