perf: audit dashboard (#9486)

Co-authored-by: feng <1304903146@qq.com>
pull/9490/head
fit2bot 2023-02-09 17:17:35 +08:00 committed by GitHub
parent 015ac4fbb6
commit 5401b1cdf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -129,10 +129,12 @@ class PasswordChangeLogViewSet(ListModelMixin, JMSGenericViewSet):
ordering = ['-datetime']
def get_queryset(self):
users = current_org.get_members()
queryset = super().get_queryset().filter(
user__in=[user.__str__() for user in users]
)
queryset = super().get_queryset()
if not current_org.is_root():
users = current_org.get_members()
queryset = queryset.filter(
user__in=[str(user) for user in users]
)
return queryset
# Todo: 看看怎么搞

View File

@ -19,7 +19,7 @@ from orgs.utils import current_org
from ops.const import JobStatus
from ops.models import Job, JobExecution
from common.utils import lazyproperty
from audits.models import UserLoginLog, PasswordChangeLog, OperateLog
from audits.models import UserLoginLog, PasswordChangeLog, OperateLog, FTPLog
from audits.const import LoginStatusChoices
from common.utils.timezone import local_now, local_zero_hour
from orgs.caches import OrgResourceStatisticsCache
@ -38,13 +38,13 @@ class DateTimeMixin:
def days(self):
query_params = self.request.query_params
count = query_params.get('days')
count = int(count) if count else 0
count = int(count) if count else 1
return count
@property
def days_to_datetime(self):
days = self.days
if days == 0:
if days == 1:
t = local_zero_hour()
else:
t = local_now() - timezone.timedelta(days=days)
@ -109,7 +109,7 @@ class DateTimeMixin:
@lazyproperty
def ftp_logs_queryset(self):
t = self.days_to_datetime
queryset = OperateLog.objects.filter(datetime__gte=t)
queryset = FTPLog.objects.filter(date_start__gte=t)
queryset = self.get_logs_queryset(queryset, 'user')
return queryset
@ -297,7 +297,7 @@ class DatesLoginMetricMixin:
@lazyproperty
def user_login_amount(self):
return self.login_logs_queryset.values('username').distinct().count()
return self.login_logs_queryset.values('username').count()
@lazyproperty
def operate_logs_amount(self):