From 173992755765eadcdc6d2a0a95a8d94f64c249b2 Mon Sep 17 00:00:00 2001 From: Jordan Robinson Date: Thu, 27 Nov 2025 23:28:51 +0000 Subject: [PATCH] fix middleware #75 --- main/middleware.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main/middleware.py b/main/middleware.py index d4a6cae3711f048f24f658f5d4ee037c65bd243d..33bfe6befbd999fb9d94d10d91aab09574f1a267 100644 --- a/main/middleware.py +++ b/main/middleware.py @@ -30,7 +30,7 @@ def host_middleware(get_response): canonical_parts = settings.CANONICAL_HOST.split(".") if host == settings.CANONICAL_HOST: - # this case is for mataroa.blog landing and dashboard pages + # this case is for bocpress.co.uk landing and dashboard pages # * don't set request.subdomain # * set theme if logged in # * return immediately @@ -39,16 +39,21 @@ def host_middleware(get_response): request.theme_sansserif = request.user.theme_sansserif return get_response(request) elif ( - len(host_parts) == 3 - and host_parts[1] == canonical_parts[0] # should be "mataroa" - and host_parts[2] == canonical_parts[1] # should be "blog" + len(host_parts) == 4 + and host_parts[1] == canonical_parts[0] # should be "bocpress" + and host_parts[2] == canonical_parts[1] # should be "co" + and host_parts[3] == canonical_parts[2] # should be "uk" ): - # this case is for .mataroa.blog: + # this case is for .bocpress.co.uk: # * set subdomain to given subdomain # * the lists indexes are different because CANONICAL_HOST has no subdomain # * also validation will happen inside views request.subdomain = host_parts[0] + allow_docs_user = False + if request.subdomain == "docs" and settings.ALLOW_DOCS_USER: + allow_docs_user = True + # check if subdomain is disallowed if request.subdomain in denylist.DISALLOWED_USERNAMES: return redirect(f"{scheme.get_protocol()}//{settings.CANONICAL_HOST}") @@ -73,7 +78,7 @@ def host_middleware(get_response): request.blog_user.custom_domain + request.path_info ) - # user has retired their mataroa blog, redirect to new domain + # user has retired their bocpress blog, redirect to new domain if request.blog_user.redirect_domain: redir_domain = ( request.blog_user.redirect_domain + request.path_info[5:] @@ -95,7 +100,7 @@ def host_middleware(get_response): request.theme_zialucia = request.blog_user.theme_zialucia request.theme_sansserif = request.blog_user.theme_sansserif - # if user has retired their mataroa blog (and keeps the custom domain) + # if user has retired their bocpress blog (and keeps the custom domain) # redirect to new domain if request.blog_user.redirect_domain: redir_domain = request.blog_user.redirect_domain + request.path_info[5:]