diff --git a/apps/audits/api.py b/apps/audits/api.py index 5ed7a9cd6..64e308699 100644 --- a/apps/audits/api.py +++ b/apps/audits/api.py @@ -2,22 +2,26 @@ # from rest_framework.viewsets import GenericViewSet from rest_framework.mixins import ListModelMixin -from django.db.models import Q from common.mixins.api import CommonApiMixin from common.permissions import IsOrgAdminOrAppUser, IsOrgAuditor, IsOrgAdmin from common.drf.filters import DatetimeRangeFilter -from orgs.mixins.api import OrgModelViewSet +from orgs.mixins.api import OrgGenericViewSet from orgs.utils import current_org from .models import FTPLog, UserLoginLog from .serializers import FTPLogSerializer, UserLoginLogSerializer -class FTPLogViewSet(OrgModelViewSet): +class FTPLogViewSet(ListModelMixin, OrgGenericViewSet): model = FTPLog serializer_class = FTPLogSerializer permission_classes = (IsOrgAdminOrAppUser | IsOrgAuditor,) - http_method_names = ['get', 'post', 'head', 'options'] + extra_filter_backends = [DatetimeRangeFilter] + date_range_filter_fields = [ + ('date_start', ('date_from', 'date_to')) + ] + filterset_fields = ['user', 'asset', 'system_user'] + search_fields = ['filename'] class UserLoginLogViewSet(CommonApiMixin, diff --git a/apps/audits/serializers.py b/apps/audits/serializers.py index 2feaed7fe..2ea0dec0f 100644 --- a/apps/audits/serializers.py +++ b/apps/audits/serializers.py @@ -11,7 +11,10 @@ class FTPLogSerializer(serializers.ModelSerializer): class Meta: model = models.FTPLog - fields = '__all__' + fields = ( + 'id', 'user', 'remote_addr', 'asset', 'system_user', + 'operate', 'filename', 'is_success', 'date_start' + ) class UserLoginLogSerializer(serializers.ModelSerializer): diff --git a/apps/orgs/mixins/api.py b/apps/orgs/mixins/api.py index 7695292c3..f3f376694 100644 --- a/apps/orgs/mixins/api.py +++ b/apps/orgs/mixins/api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # from django.shortcuts import get_object_or_404 -from rest_framework.viewsets import ModelViewSet +from rest_framework.viewsets import ModelViewSet, GenericViewSet from rest_framework_bulk import BulkModelViewSet from common.mixins import CommonApiMixin @@ -44,6 +44,10 @@ class OrgModelViewSet(CommonApiMixin, OrgQuerySetMixin, ModelViewSet): pass +class OrgGenericViewSet(CommonApiMixin, OrgQuerySetMixin, GenericViewSet): + pass + + class OrgBulkModelViewSet(CommonApiMixin, OrgQuerySetMixin, BulkModelViewSet): def allow_bulk_destroy(self, qs, filtered): qs_count = qs.count()