From 75696e2b740ca01e34cf55a24132e165495aa14b Mon Sep 17 00:00:00 2001 From: A7640S Date: Fri, 18 Jul 2025 16:27:44 +0000 Subject: [PATCH] middleware of tenant --- Mapapi/middleware.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Mapapi/middleware.py b/Mapapi/middleware.py index 9e010cd..73120ab 100644 --- a/Mapapi/middleware.py +++ b/Mapapi/middleware.py @@ -6,14 +6,16 @@ class OrganisationFromSubdomainMiddleware(MiddlewareMixin): Middleware pour extraire le sous-domaine de la requête et attacher l'organisation à request.organisation """ def process_request(self, request): - host = request.get_host().split(':')[0] # retire le port éventuel - # On suppose que le domaine principal est map-action.com - # et que le sous-domaine correspond à l'organisation - parts = host.split('.') - if len(parts) < 2: + subdomain = request.META.get('HTTP_X_TENANT_SUBDOMAIN') + if not subdomain: + host = request.get_host().split(':')[0] + parts = host.split('.') + subdomain = parts[0] if len(parts) > 2 else None + + if not subdomain: request.organisation = None return - subdomain = parts[0] + try: organisation = Organisation.objects.get(subdomain=subdomain) request.organisation = organisation