Browse Source

Refactor: Remove inline `get_admin_namespace` function from `enhanced_auth_middleware.py`

- Eliminated the inline `get_admin_namespace` function to streamline the code and improve readability.
- The function is now imported from the centralized `config.middleware` module, enhancing code organization and reusability.
master
mortezaei 3 months ago
parent
commit
4b32500888
  1. 15
      config/enhanced_auth_middleware.py

15
config/enhanced_auth_middleware.py

@ -3,24 +3,11 @@ from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.urls import reverse
from django.contrib import messages
from config.middleware import get_admin_namespace
User = get_user_model()
def get_admin_namespace(request):
"""
Determine the admin namespace based on the request domain.
Returns the appropriate admin namespace for use in reverse() calls.
"""
host = request.get_host()
# Check if the request is from Dovoodi domain
if 'dovodi' in host or 'dovoodi' in host:
return 'dovoodi_admin'
else:
return 'imam_javad_admin'
def enhanced_auth_middleware(get_response):
"""
Enhanced middleware for API authentication with admin restriction

Loading…
Cancel
Save