mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-24 10:54:05 +01:00
fixed test
This commit is contained in:
@@ -11,13 +11,12 @@ from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.permissions import DjangoModelPermissions, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from modoboa.core import models as core_models
|
||||
from modoboa.core import sms_backends
|
||||
from modoboa.lib import renderers as lib_renderers
|
||||
from modoboa.lib import viewsets as lib_viewsets
|
||||
from modoboa.lib.throttle import UserDdosPerView, GetThrottleViewsetMixin, PasswordResetRequestThrottle
|
||||
from modoboa.lib.throttle import GetThrottleViewsetMixin, PasswordResetRequestThrottle
|
||||
|
||||
from ... import lib, models
|
||||
from . import serializers
|
||||
@@ -91,11 +90,11 @@ class AccountViewSet(GetThrottleViewsetMixin, lib_viewsets.RevisionModelMixin, v
|
||||
|
||||
def get_throttles(self):
|
||||
|
||||
throttle_classes = super().get_throttles()
|
||||
throttles = super().get_throttles()
|
||||
if self.action == "reset_password":
|
||||
throttle_classes.append(PasswordResetRequestThrottle())
|
||||
throttles.append(PasswordResetRequestThrottle())
|
||||
|
||||
return throttle_classes
|
||||
return throttles
|
||||
|
||||
def get_serializer_class(self):
|
||||
"""Return a serializer."""
|
||||
|
||||
@@ -11,13 +11,12 @@ from rest_framework import (
|
||||
)
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from modoboa.admin.api.v1 import viewsets as v1_viewsets
|
||||
from modoboa.core import models as core_models
|
||||
from modoboa.lib import renderers as lib_renderers
|
||||
from modoboa.lib import viewsets as lib_viewsets
|
||||
from modoboa.lib.throttle import UserDdosPerView, UserLesserDdosUser, GetThrottleViewsetMixin
|
||||
from modoboa.lib.throttle import GetThrottleViewsetMixin
|
||||
|
||||
from ... import lib
|
||||
from ... import models
|
||||
|
||||
@@ -8,7 +8,6 @@ from django_otp.plugins.otp_totp.models import TOTPDevice
|
||||
|
||||
from rest_framework import permissions, response, viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
|
||||
@@ -11,14 +11,13 @@ from rest_framework import filters, permissions, response, viewsets
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from modoboa.admin.api.v1 import serializers as admin_v1_serializers
|
||||
from modoboa.core.api.v1 import serializers as core_v1_serializers
|
||||
from modoboa.core.api.v1 import viewsets as core_v1_viewsets
|
||||
from modoboa.lib import pagination
|
||||
from modoboa.lib.throttle import UserLesserDdosUser, UserDdosPerView, GetThrottleViewsetMixin
|
||||
from modoboa.lib.throttle import GetThrottleViewsetMixin
|
||||
|
||||
from ... import constants
|
||||
from ... import models
|
||||
@@ -150,7 +149,7 @@ class AccountViewSet(core_v1_viewsets.AccountViewSet):
|
||||
})
|
||||
|
||||
|
||||
class LogViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
class LogViewSet(GetThrottleViewsetMixin, viewsets.ReadOnlyModelViewSet):
|
||||
"""Log viewset."""
|
||||
|
||||
filter_backends = [filters.OrderingFilter, filters.SearchFilter]
|
||||
@@ -164,16 +163,14 @@ class LogViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = models.Log.objects.all()
|
||||
search_fields = ["logger", "level", "message"]
|
||||
serializer_class = serializers.LogSerializer
|
||||
throttle_classes = [UserRateThrottle]
|
||||
|
||||
|
||||
class LanguageViewSet(viewsets.ViewSet):
|
||||
class LanguageViewSet(GetThrottleViewsetMixin, viewsets.ViewSet):
|
||||
"""Language viewset."""
|
||||
|
||||
permission_classes = (
|
||||
permissions.IsAuthenticated,
|
||||
)
|
||||
throttle_classes = [UserRateThrottle]
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
languages = [
|
||||
|
||||
@@ -70,10 +70,10 @@ class GetThrottleViewsetMixin():
|
||||
def get_throttles(self):
|
||||
"""Give lesser_ddos to GET type actions and ddos to others."""
|
||||
|
||||
throttle_classes = [UserRateThrottle()]
|
||||
throttles = [UserRateThrottle()]
|
||||
|
||||
if self.action in ["list", "retrieve", "validate", "dns_detail", "me", "dns_detail"]:
|
||||
throttle_classes.append(UserLesserDdosUser())
|
||||
if self.action in ["list", "retrieve", "validate", "dns_detail", "me", "dns_detail", "applications", "structure"]:
|
||||
throttles.append(UserLesserDdosUser())
|
||||
else:
|
||||
throttle_classes.append(UserDdosPerView())
|
||||
return throttle_classes
|
||||
throttles.append(UserDdosPerView())
|
||||
return throttles
|
||||
@@ -3,7 +3,6 @@
|
||||
from drf_spectacular.utils import extend_schema, OpenApiParameter
|
||||
from rest_framework import response, viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from modoboa.lib.throttle import GetThrottleViewsetMixin
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import DjangoModelPermissions, IsAuthenticated
|
||||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
from modoboa.admin import models as admin_models
|
||||
from modoboa.lib.throttle import GetThrottleViewsetMixin
|
||||
|
||||
Reference in New Issue
Block a user