π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
fix: adding throttling at base api view for external apis
vamsia5a449680086
diff --git a/apiserver/plane/api/views/base.py b/apiserver/plane/api/views/base.pyindex fee508a30c..a3241eaf3b 100644--- a/apiserver/plane/api/views/base.py+++ b/apiserver/plane/api/views/base.py@@ -7,6 +7,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom django.db import IntegrityErrorfrom django.urls import resolvefrom django.utils import timezone+from plane.db.models.api import APITokenfrom rest_framework import statusfrom rest_framework.permissions import IsAuthenticatedfrom rest_framework.response import Response@@ -16,7 +17,7 @@ from rest_framework.views import APIView# Module importsfrom plane.api.middleware.api_authentication import APIKeyAuthentication-from plane.api.rate_limit import ApiKeyRateThrottle+from plane.api.rate_limit import ApiKeyRateThrottle, ServiceTokenRateThrottlefrom plane.utils.exception_logger import log_exceptionfrom plane.utils.paginator import BasePaginator@@ -44,15 +45,29 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):IsAuthenticated,]- throttle_classes = [- ApiKeyRateThrottle,- ]-def filter_queryset(self, queryset):for backend in list(self.filter_backends):queryset = backend().filter_queryset(self.request, queryset, self)return queryset+ def get_throttles(self):+ throttle_classes = []+ api_key = self.request.headers.get("X-Api-Key")++ if api_key:+ service_token = APIToken.objects.filter(+ token=api_key,+ is_service=True,+ ).first()++ if service_token:+ throttle_classes.append(ServiceTokenRateThrottle())+ return throttle_classes++ throttle_classes.append(ApiKeyRateThrottle())++ return throttle_classes+def handle_exception(self, exc):"""Handle any exception that occurs, by returning an appropriate response,@@ -152,4 +167,4 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):for expand in self.request.GET.get("expand", "").split(",")if expand]- return expand if expand else None+ return expand if expand else None\ No newline at end of file