From 1acad723a9110839d5b2ccb65e3f735c5cfd0de3 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Wed, 16 Jan 2019 11:24:26 +0000
Subject: [PATCH] Remove the public search and newsletter urls from the apply
 site

---
 opentech/apply/urls.py |  2 +-
 opentech/urls.py       | 34 +++++++++++++++++++++++++---------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/opentech/apply/urls.py b/opentech/apply/urls.py
index 27483633b..662aa72b2 100644
--- a/opentech/apply/urls.py
+++ b/opentech/apply/urls.py
@@ -3,7 +3,7 @@ from django.urls import include, path
 from .users import urls as users_urls
 from .dashboard import urls as dashboard_urls
 
-from opentech.urls import urlpatterns as base_urlpatterns
+from opentech.urls import base_urlpatterns
 
 
 urlpatterns = [
diff --git a/opentech/urls.py b/opentech/urls.py
index 8cb2fe306..de6766aa9 100644
--- a/opentech/urls.py
+++ b/opentech/urls.py
@@ -14,13 +14,25 @@ from opentech.public import urls as public_urls
 from opentech.apply.users.urls import public_urlpatterns as user_urls
 
 
+def apply_cache_control(*patterns):
+    # Cache-control
+    cache_length = getattr(settings, 'CACHE_CONTROL_MAX_AGE', None)
+
+    if cache_length:
+        patterns = decorate_urlpatterns(
+            patterns,
+            cache_control(max_age=cache_length)
+        )
+
+    return list(patterns)
+
+
 urlpatterns = [
     path('django-admin/', admin.site.urls),
     path('admin/', include(wagtailadmin_urls)),
 
     path('documents/', include(wagtaildocs_urls)),
     path('sitemap.xml', sitemap),
-    path('', include(public_urls)),
     path('', include((user_urls, 'users_public'))),
     path('', include('social_django.urls', namespace='social')),
     path('tinymce/', include('tinymce.urls')),
@@ -52,18 +64,22 @@ urlpatterns += [
     path('', include(wagtail_urls)),
 ]
 
+urlpatterns = apply_cache_control(*urlpatterns)
 
-# Cache-control
-cache_length = getattr(settings, 'CACHE_CONTROL_MAX_AGE', None)
-
-if cache_length:
-    urlpatterns = decorate_urlpatterns(
-        urlpatterns,
-        cache_control(max_age=cache_length)
-    )
 
 if settings.DEBUG and settings.DEBUGTOOLBAR:
     import debug_toolbar
     urlpatterns = [
         path('__debug__/', include(debug_toolbar.urls)),
     ] + urlpatterns
+
+
+base_urlpatterns = [*urlpatterns]
+
+
+# Add in URLs only available to the public site
+# Place before the wagtail urls without mutating the object
+urlpatterns.insert(
+    -1,
+    *apply_cache_control(path('', include(public_urls)))
+)
-- 
GitLab