mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
fixed test
This commit is contained in:
@@ -3,7 +3,6 @@ import Cookies from 'js-cookie'
|
||||
|
||||
import router from '../router'
|
||||
import store from '../store'
|
||||
import app from '../App.vue'
|
||||
|
||||
const _axios = axios.create()
|
||||
|
||||
@@ -33,7 +32,7 @@ _axios.interceptors.response.use(
|
||||
return Promise.reject(error)
|
||||
}
|
||||
if (error.response.status === 429) {
|
||||
app.showNotification()
|
||||
store.showNotification()
|
||||
return Promise.reject(error)
|
||||
}
|
||||
if (error.response.status !== 401 || router.currentRoute.path === '/login/') {
|
||||
|
||||
@@ -89,6 +89,7 @@ export default {
|
||||
this.$router.push({ name: 'DomainList' })
|
||||
})
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
this.loading = false
|
||||
if (err.response.status === 401) {
|
||||
this.$refs.observer.setErrors({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -187,13 +187,13 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_THROTTLE_RATES': {
|
||||
'user': '400/minute',
|
||||
'ddos': '100/second',
|
||||
'ddos_lesser': '300/minute',
|
||||
'user': '200/minute',
|
||||
'ddos': '10/second',
|
||||
'ddos_lesser': '200/minute',
|
||||
'login': '10/minute',
|
||||
'password_recovery_request': '6/hour',
|
||||
'password_recovery_totp_check': '40/hour',
|
||||
'password_recovery_apply': '40/hour'
|
||||
'password_recovery_request': '11/hour',
|
||||
'password_recovery_totp_check': '25/hour',
|
||||
'password_recovery_apply': '25/hour'
|
||||
},
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'modoboa.core.drf_authentication.JWTAuthenticationWith2FA',
|
||||
|
||||
Reference in New Issue
Block a user