Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/throttling.py
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def get_exempted_networks(self, scope_name: str | ||||
if scope: | if scope: | ||||
networks = scope.get('exempted_networks') | networks = scope.get('exempted_networks') | ||||
if networks: | if networks: | ||||
self.exempted_networks = [ip_network(network) | self.exempted_networks = [ip_network(network) | ||||
for network in networks] | for network in networks] | ||||
return self.exempted_networks | return self.exempted_networks | ||||
def allow_request(self, request: Request, view: APIView) -> bool: | def allow_request(self, request: Request, view: APIView) -> bool: | ||||
# no throttling for staff users | |||||
if request.user.is_authenticated and request.user.is_staff: | |||||
return True | |||||
# class based view case | # class based view case | ||||
if not self.scope: | if not self.scope: | ||||
default_scope = getattr(view, self.scope_attr, None) | default_scope = getattr(view, self.scope_attr, None) | ||||
request_allowed = None | request_allowed = None | ||||
if default_scope is not None: | if default_scope is not None: | ||||
# check if there is a specific rate limiting associated | # check if there is a specific rate limiting associated | ||||
# to the request type | # to the request type | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |