From 5de2ace0bab0d7946bf3100aaaaaad52e9f820b0 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Tue, 3 Feb 2026 13:34:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20refactor=20thrott?= =?UTF-8?q?ling=20classes=20into=20a=20dedicated=20Python=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prepares the ground for introducing the LaSuite Django observability pattern, including Sentry integration. --- src/backend/core/api/throttling.py | 15 +++++++++++++++ src/backend/core/api/viewsets.py | 20 ++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 src/backend/core/api/throttling.py diff --git a/src/backend/core/api/throttling.py b/src/backend/core/api/throttling.py new file mode 100644 index 00000000..ba343485 --- /dev/null +++ b/src/backend/core/api/throttling.py @@ -0,0 +1,15 @@ +"""Throttling handlers for the Meet core app.""" + +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.py index 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 Http404 from django.shortcuts import get_object_or_404 from django.utils.text import slugify -from rest_framework import decorators, mixins, pagination, throttling, viewsets +from rest_framework import decorators, mixins, pagination, viewsets from rest_framework import ( exceptions as drf_exceptions, ) @@ -58,7 +58,7 @@ from core.services.room_creation import RoomCreation from core.services.subtitle import SubtitleException, SubtitleService from ..authentication.livekit import LiveKitTokenAuthentication -from . import permissions, serializers +from . import permissions, serializers, throttling from .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.