File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ from django .conf import settings
2+ from django .http import HttpResponseRedirect
3+
4+
5+ class AdminRedirectMiddleware :
6+ def __init__ (self , get_response ):
7+ self .get_response = get_response
8+
9+ def __call__ (self , request ):
10+ # Check if the request is for the admin site and the user is not a superuser
11+ if settings .SECRET_ADMIN_PREFIX in request .path and not request .user .is_superuser :
12+ # Remove the '/admin' prefix and redirect to the CRM site's URL
13+ new_path = request .path .replace (
14+ settings .SECRET_ADMIN_PREFIX , settings .SECRET_CRM_PREFIX )
15+ query_string = request .META .get ('QUERY_STRING' )
16+ if query_string :
17+ new_path = f"{ new_path } ?{ query_string } "
18+ return HttpResponseRedirect (new_path )
19+ return self .get_response (request )
Original file line number Diff line number Diff line change 131131 'django.contrib.auth.middleware.AuthenticationMiddleware' ,
132132 'django.contrib.messages.middleware.MessageMiddleware' ,
133133 'django.middleware.clickjacking.XFrameOptionsMiddleware' ,
134+ 'common.utils.admin_redirect_middleware.AdminRedirectMiddleware' ,
134135 'common.utils.usermiddleware.UserMiddleware'
135136]
136137
You can’t perform that action at this time.
0 commit comments