forked from SlavaSkvortsov/arq-django-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_middleware.py
More file actions
42 lines (31 loc) · 1.12 KB
/
Copy pathdocker_middleware.py
File metadata and controls
42 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Middleware to bypass authentication for arq-dashboard in Docker.
WARNING: Use only in secure/internal environments.
"""
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
class MockUser:
"""Mock authenticated staff user."""
is_authenticated = True
is_staff = True
is_active = True
is_superuser = False
username = 'docker-user'
def __str__(self):
return self.username
def has_perm(self, perm, obj=None):
return True
def has_perms(self, perm_list, obj=None):
return True
def has_module_perms(self, module):
return True
class BypassAuthenticationMiddleware:
"""Middleware that makes all users appear as staff for arq-dashboard access."""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Replace anonymous users with mock authenticated staff
if isinstance(request.user, AnonymousUser) or not request.user.is_authenticated:
request.user = MockUser()
response = self.get_response(request)
return response