Open source video conferencing app powered by LiveKit. Built with Django and React.
♻️(backend) extract throttling classes into a module
lebaudantoine23de7e52bcbc
diff --git a/src/backend/core/api/throttling.py b/src/backend/core/api/throttling.pynew file mode 100644index 00000000..2738bfc8--- /dev/null+++ b/src/backend/core/api/throttling.py@@ -0,0 +1,14 @@+"""Throttling modules for the API."""++from rest_framework import throttling++class RequestEntryAnonRateThrottle(throttling.AnonRateThrottle):+ """Throttle Anonymous user requesting room entry"""++ scope = "request_entry"+++class CreationCallbackAnonRateThrottle(throttling.AnonRateThrottle):+ """Throttle Anonymous user requesting room generation callback"""++ scope = "creation_callback"diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.pyindex 0d1349ed..15159770 100644--- a/src/backend/core/api/viewsets.py+++ b/src/backend/core/api/viewsets.py@@ -10,7 +10,7 @@ from django.http import Http404from django.shortcuts import get_object_or_404from django.utils.text import slugify-from rest_framework import decorators, mixins, pagination, throttling, viewsets+from rest_framework import decorators, mixins, pagination, viewsetsfrom rest_framework import (exceptions as drf_exceptions,)@@ -58,7 +58,7 @@ from core.services.room_creation import RoomCreationfrom core.services.subtitle import SubtitleException, SubtitleServicefrom ..authentication.livekit import LiveKitTokenAuthentication-from . import permissions, serializers+from . import permissions, serializers, throttlingfrom .feature_flag import FeatureFlag# pylint: disable=too-many-ancestors@@ -191,18 +191,6 @@ class UserViewSet()-class RequestEntryAnonRateThrottle(throttling.AnonRateThrottle):- """Throttle Anonymous user requesting room entry"""-- scope = "request_entry"---class CreationCallbackAnonRateThrottle(throttling.AnonRateThrottle):- """Throttle Anonymous user requesting room generation callback"""-- scope = "creation_callback"--class RoomViewSet(mixins.CreateModelMixin,mixins.DestroyModelMixin,@@ -379,7 +367,7 @@ class RoomViewSet(methods=["post"],url_path="request-entry",permission_classes=[],- throttle_classes=[RequestEntryAnonRateThrottle],+ throttle_classes=[throttling.RequestEntryAnonRateThrottle],)def request_entry(self, request, pk=None): # pylint: disable=unused-argument"""Request entry to a room"""@@ -489,7 +477,7 @@ class RoomViewSet(methods=["post"],url_path="creation-callback",permission_classes=[],- throttle_classes=[CreationCallbackAnonRateThrottle],+ throttle_classes=[throttling.CreationCallbackAnonRateThrottle],)def creation_callback(self, request):"""Retrieve cached room data via an unauthenticated request with a unique ID.