2022-08-14 11:35:03 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.auth.middleware import RemoteUserMiddleware
|
|
|
|
|
2024-08-31 18:25:43 +00:00
|
|
|
from bookmarks.models import UserProfile, GlobalSettings
|
2023-08-14 22:20:52 +00:00
|
|
|
|
2022-08-14 11:35:03 +00:00
|
|
|
|
|
|
|
class CustomRemoteUserMiddleware(RemoteUserMiddleware):
|
|
|
|
header = settings.LD_AUTH_PROXY_USERNAME_HEADER
|
2023-08-14 22:20:52 +00:00
|
|
|
|
|
|
|
|
2024-09-14 09:32:19 +00:00
|
|
|
default_global_settings = GlobalSettings()
|
|
|
|
|
2024-08-31 18:25:43 +00:00
|
|
|
standard_profile = UserProfile()
|
|
|
|
standard_profile.enable_favicons = True
|
|
|
|
|
|
|
|
|
2024-09-14 09:32:19 +00:00
|
|
|
class LinkdingMiddleware:
|
2023-08-14 22:20:52 +00:00
|
|
|
def __init__(self, get_response):
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
|
|
def __call__(self, request):
|
2024-09-14 09:32:19 +00:00
|
|
|
# add global settings to request
|
|
|
|
try:
|
|
|
|
global_settings = GlobalSettings.get()
|
|
|
|
except:
|
|
|
|
global_settings = default_global_settings
|
|
|
|
request.global_settings = global_settings
|
|
|
|
|
|
|
|
# add user profile to request
|
2023-08-14 22:20:52 +00:00
|
|
|
if request.user.is_authenticated:
|
|
|
|
request.user_profile = request.user.profile
|
|
|
|
else:
|
2024-08-31 18:25:43 +00:00
|
|
|
# check if a custom profile for guests exists, otherwise use standard profile
|
2024-09-14 09:32:19 +00:00
|
|
|
if global_settings.guest_profile_user:
|
|
|
|
request.user_profile = global_settings.guest_profile_user.profile
|
|
|
|
else:
|
|
|
|
request.user_profile = standard_profile
|
2023-08-14 22:20:52 +00:00
|
|
|
|
|
|
|
response = self.get_response(request)
|
|
|
|
|
|
|
|
return response
|