Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Mapapi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down