File tree Expand file tree Collapse file tree 3 files changed +8
-37
lines changed Expand file tree Collapse file tree 3 files changed +8
-37
lines changed Original file line number Diff line number Diff line change @@ -259,13 +259,12 @@ def test_api_with_single_vulnerability_and_vulnerable_package(self):
259259 }
260260
261261 def test_api_with_all_vulnerable_packages (self ):
262- with self .assertNumQueries (5 ):
262+ with self .assertNumQueries (4 ):
263263 # There are 4 queries:
264264 # 1. SAVEPOINT
265265 # 2. Authenticating user
266- # 3. Checking if user is staff user for throttling purposes
267- # 4. Get all vulnerable packages
268- # 5. RELEASE SAVEPOINT
266+ # 3. Get all vulnerable packages
267+ # 4. RELEASE SAVEPOINT
269268 response = self .csrf_client .get (f"/api/packages/all" , format = "json" ).data
270269 assert len (response ) == 11
271270 assert response == [
Original file line number Diff line number Diff line change 1313User = get_user_model ()
1414
1515
16- class ExceptionalUserRateThrottle (UserRateThrottle ):
16+ class StaffUserRateThrottle (UserRateThrottle ):
1717 def allow_request (self , request , view ):
1818 """
19- Give special access to a few special accounts.
20-
21- Mirrors code in super class with minor tweaks.
19+ Do not apply throttling for superusers and admins.
2220 """
23- if self .rate is None :
24- return True
25-
26- self .key = self .get_cache_key (request , view )
27- if self .key is None :
21+ if request .user .is_superuser or request .user .is_staff :
2822 return True
2923
30- self .history = self .cache .get (self .key , [])
31- self .now = self .timer ()
32-
33- # Adjust if user has special privileges.
34-
35- user = User .objects .get (username = request .user .username )
36-
37- if user :
38- if user .is_superuser or user .is_staff :
39- # No throttling for superusers or staff.
40- return True
41-
42- else :
43- self .num_requests = self .num_requests
44- self .duration = self .duration
45-
46- # Drop any requests from the history which have now passed the
47- # throttle duration
48- while self .history and self .history [- 1 ] <= self .now - self .duration :
49- self .history .pop ()
50- if len (self .history ) >= self .num_requests :
51- return self .throttle_failure ()
52- return self .throttle_success ()
24+ return super ().allow_request (request , view )
Original file line number Diff line number Diff line change 188188 "rest_framework.filters.SearchFilter" ,
189189 ),
190190 "DEFAULT_THROTTLE_CLASSES" : [
191- "vulnerabilities.throttling.ExceptionalUserRateThrottle " ,
191+ "vulnerabilities.throttling.StaffUserRateThrottle " ,
192192 ],
193193 "DEFAULT_THROTTLE_RATES" : {"user" : THROTTLING_RATE },
194194 "DEFAULT_PAGINATION_CLASS" : "vulnerabilities.pagination.SmallResultSetPagination" ,
You can’t perform that action at this time.
0 commit comments