Skip to content

Commit 0f9f528

Browse files
authored
Merge pull request #15 from 223MapAction/dev
middleware of tenant
2 parents f53bb80 + 75696e2 commit 0f9f528

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Mapapi/middleware.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ class OrganisationFromSubdomainMiddleware(MiddlewareMixin):
66
Middleware pour extraire le sous-domaine de la requête et attacher l'organisation à request.organisation
77
"""
88
def process_request(self, request):
9-
host = request.get_host().split(':')[0] # retire le port éventuel
10-
# On suppose que le domaine principal est map-action.com
11-
# et que le sous-domaine correspond à l'organisation
12-
parts = host.split('.')
13-
if len(parts) < 2:
9+
subdomain = request.META.get('HTTP_X_TENANT_SUBDOMAIN')
10+
if not subdomain:
11+
host = request.get_host().split(':')[0]
12+
parts = host.split('.')
13+
subdomain = parts[0] if len(parts) > 2 else None
14+
15+
if not subdomain:
1416
request.organisation = None
1517
return
16-
subdomain = parts[0]
18+
1719
try:
1820
organisation = Organisation.objects.get(subdomain=subdomain)
1921
request.organisation = organisation

0 commit comments

Comments
 (0)