From 4b325008889bd8da0d432509127f21a0b046fd20 Mon Sep 17 00:00:00 2001 From: mortezaei Date: Sun, 8 Feb 2026 13:38:41 +0330 Subject: [PATCH] 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. --- config/enhanced_auth_middleware.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/config/enhanced_auth_middleware.py b/config/enhanced_auth_middleware.py index 9129b42..c2da2bc 100644 --- a/config/enhanced_auth_middleware.py +++ b/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