Skip to content

Commit

Permalink
Deprecate SERVE_LATEST_DRAFT_PAGES setting
Browse files Browse the repository at this point in the history
This commit deprecates the `SERVE_LATEST_DRAFT_PAGES` that allows for
arbitrary serving of draft Wagtail page content by primary key. This
functionality was added in 2017 in commit
e8902bd for a few pages and then
turned off for those pages in 2018 in commit
ae0156d. It hasn't been used since.

We now use wagtail-sharing to provide this functionality instead.
  • Loading branch information
chosak committed Aug 9, 2023
1 parent eefc258 commit e4ab038
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
9 changes: 0 additions & 9 deletions cfgov/cfgov/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,6 @@
"ROBOTS_TXT_SEARCH_GOV_ONLY": [("environment is", "beta")],
}

# We want the ability to serve the latest drafts of some pages on beta
# This value is read by v1.wagtail_hooks
SERVE_LATEST_DRAFT_PAGES = []

# To expose a previously-published page's latest draft version on beta,
# add its primary key to the list below
if DEPLOY_ENVIRONMENT == "beta":
SERVE_LATEST_DRAFT_PAGES = []

# Email popup configuration. See v1.templatetags.email_popup.
EMAIL_POPUP_URLS = {
"debt": [
Expand Down
31 changes: 2 additions & 29 deletions cfgov/v1/tests/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from django.contrib.auth.models import Permission, User
from django.core.exceptions import PermissionDenied
from django.test import (
RequestFactory,
SimpleTestCase,
TestCase,
override_settings,
)
from django.test import RequestFactory, SimpleTestCase, TestCase
from django.urls import reverse

from wagtail import hooks
from wagtail.admin.views.pages.bulk_actions.delete import DeleteBulkAction
from wagtail.admin.views.pages.delete import delete
from wagtail.models import Page, Site
from wagtail.test.testapp.models import SimplePage
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils
from wagtail.whitelist import Whitelister as Allowlister

Expand All @@ -27,27 +21,6 @@
)


class TestServeLatestDraftPage(TestCase):
def setUp(self):
self.default_site = Site.objects.get(is_default_site=True)
self.page = SimplePage(title="live", slug="test", content="test")
self.default_site.root_page.add_child(instance=self.page)
self.page.title = "draft"
self.page.save_revision()

@override_settings(SERVE_LATEST_DRAFT_PAGES=[])
def test_not_serving_draft_serves_published_revision(self):
response = self.client.get("/test/")
self.assertContains(response, "live")
self.assertIsNone(response.get("Serving-Wagtail-Draft"))

def test_serving_draft_serves_latest_revision_and_adds_header(self):
with override_settings(SERVE_LATEST_DRAFT_PAGES=[self.page.pk]):
response = self.client.get("/test/")
self.assertContains(response, "draft")
self.assertEqual(response["Serving-Wagtail-Draft"], "1")


class TestGetResourceTags(TestCase):
def setUp(self):
self.resource1 = Resource.objects.create(title="Test resource 1")
Expand Down
9 changes: 0 additions & 9 deletions cfgov/v1/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,6 @@ def register_cdn_url():
]


@hooks.register("before_serve_page")
def serve_latest_draft_page(page, request, args, kwargs):
if page.pk in settings.SERVE_LATEST_DRAFT_PAGES:
latest_draft = page.get_latest_revision_as_object()
response = latest_draft.serve(request, *args, **kwargs)
response["Serving-Wagtail-Draft"] = "1"
return response


@hooks.register("register_reports_menu_item")
def register_page_metadata_report_menu_item():
return MenuItem(
Expand Down

0 comments on commit e4ab038

Please sign in to comment.