Files
Pinry/users/middleware.py
winkidney 374be7a03f Fix: Fix test failure cased by new django-test client response
+ Also fix the old middleware
+ Fix MIDDLEWARE name error
2020-07-17 21:49:17 +08:00

17 lines
493 B
Python

from django.conf import settings
from django.http import HttpResponseForbidden
from django.utils.deprecation import MiddlewareMixin
class Public(MiddlewareMixin):
acceptable_paths = (
"/api/v2/profile/",
)
def process_request(self, request):
if settings.PUBLIC is False and not request.user.is_authenticated:
for path in self.acceptable_paths:
if not request.path.startswith(path):
return HttpResponseForbidden()