Ensure "recent edits" panel works when page record is missing

Fixes #9185
pull/9239/head
Matt Westcott 2022-09-20 18:03:35 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 882ed28359
commit cb009d1c01
4 zmienionych plików z 26 dodań i 5 usunięć

Wyświetl plik

@ -56,6 +56,7 @@ Changelog
* Fix: Prevent JS error on images index view when collections dropdown is omitted (Tidiane Dia)
* Fix: Prevent "Entries per page" dropdown on images index view from reverting to 10 (Tidiane Dia)
* Fix: Set related_name on user revision relation to avoid conflict with django-reversion (Matt Westcott)
* Fix: Ensure the "recent edits" panel on the Dashboard (home) page works when page record is missing (Matt Westcott)
4.0.1 (05.09.2022)

Wyświetl plik

@ -31,3 +31,4 @@ depth: 1
* Prevent JS error on images index view when collections dropdown is omitted (Tidiane Dia)
* Prevent "Entries per page" dropdown on images index view from reverting to 10 (Tidiane Dia)
* Set related_name on user revision relation to avoid conflict with django-reversion (Matt Westcott)
* Ensure the "recent edits" panel on the Dashboard (home) page works when page record is missing (Matt Westcott)

Wyświetl plik

@ -20,10 +20,11 @@ class TestRecentEditsPanel(TestCase, WagtailTestUtils):
content="Some content here",
)
self.root_page.add_child(instance=child_page)
child_page.save_revision().publish()
self.revision = child_page.save_revision()
self.revision.publish()
self.child_page = SimplePage.objects.get(id=child_page.id)
self.create_superuser(username="alice", password="password")
self.user_alice = self.create_superuser(username="alice", password="password")
self.create_superuser(username="bob", password="password")
def change_something(self, title):
@ -81,6 +82,21 @@ class TestRecentEditsPanel(TestCase, WagtailTestUtils):
response = self.go_to_dashboard_response()
self.assertIn("Your most recent edits", response.content.decode("utf-8"))
def test_missing_page_record(self):
# Ensure that the panel still renders when one of the returned revision records
# has no corresponding Page object. It's unclear how this happens, since revisions
# are deleted on page deletion, but there are reports of this happening in
# https://github.com/wagtail/wagtail/issues/9185
# edit the revision object to be owned by Alice and have an unrecognised object ID
self.revision.user = self.user_alice
self.revision.object_id = "999999"
self.revision.save()
self.login(username="alice", password="password")
response = self.client.get(reverse("wagtailadmin_home"))
self.assertEqual(response.status_code, 200)
def test_panel(self):
"""Test if the panel actually returns expected pages"""
self.login(username="bob", password="password")

Wyświetl plik

@ -207,9 +207,12 @@ class RecentEditsPanel(Component):
# The revision's object_id is a string, so cast it to int first.
page_keys = [int(pr.object_id) for pr in last_edits]
pages = Page.objects.specific().in_bulk(page_keys)
context["last_edits"] = [
[revision, pages.get(int(revision.object_id))] for revision in last_edits
]
context["last_edits"] = []
for revision in last_edits:
page = pages.get(int(revision.object_id))
if page:
context["last_edits"].append([revision, page])
context["request"] = request
return context