From 3376060ea6e05757cf08493c19bb49773096e435 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Wed, 18 Oct 2023 23:28:22 -0400 Subject: [PATCH] Use the correct action log when creating a redirect --- CHANGELOG.txt | 1 + docs/releases/5.2.md | 1 + wagtail/contrib/redirects/tests/test_redirects.py | 10 ++++++++-- wagtail/contrib/redirects/views.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e016f32efa..243727f9f6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -69,6 +69,7 @@ Changelog * Fix: Avoid forgotten password link text conflicting with the supplied aria-label (Thibaud Colas) * Fix: Fix log message to record the correct restriction type when removing a page view restriction (Rohit Sharma, Hazh. M. Adam) * Fix: Avoid potential race condition with new Page subscriptions on the edit view (Alex Tomkins) + * Fix: Use the correct action log when creating a redirect (Thibaud Colas) * Docs: Document `WAGTAILADMIN_BASE_URL` on "Integrating Wagtail into a Django project" page (Shreshth Srivastava) * Docs: Replace incorrect screenshot for authors listing on tutorial (Shreshth Srivastava) * Docs: Add documentation for building non-model-based choosers using the _queryish_ library (Matt Westcott) diff --git a/docs/releases/5.2.md b/docs/releases/5.2.md index 4803c14bd5..aeaa2a6d31 100644 --- a/docs/releases/5.2.md +++ b/docs/releases/5.2.md @@ -93,6 +93,7 @@ This feature was developed by Paarth Agarwal and Thibaud Colas as part of the Go * Avoid forgotten password link text conflicting with the supplied aria-label (Thibaud Colas) * Fix log message to record the correct restriction type when removing a page view restriction (Rohit Sharma, Hazh. M. Adam) * Avoid potential race condition with new Page subscriptions on the edit view (Alex Tomkins) + * Use the correct action log when creating a redirect (Thibaud Colas) ### Documentation diff --git a/wagtail/contrib/redirects/tests/test_redirects.py b/wagtail/contrib/redirects/tests/test_redirects.py index 4e868aeb43..d6e8729ea6 100644 --- a/wagtail/contrib/redirects/tests/test_redirects.py +++ b/wagtail/contrib/redirects/tests/test_redirects.py @@ -3,6 +3,7 @@ from django.urls import reverse from wagtail.admin.admin_url_finder import AdminURLFinder from wagtail.contrib.redirects import models +from wagtail.log_actions import registry as log_registry from wagtail.models import Page, Site from wagtail.test.routablepage.models import RoutablePageTest from wagtail.test.utils import WagtailTestUtils @@ -653,9 +654,14 @@ class TestRedirectsAddView(WagtailTestUtils, TestCase): # Check that the redirect was created redirects = models.Redirect.objects.filter(old_path="/test") + redirect = redirects.first() self.assertEqual(redirects.count(), 1) - self.assertEqual(redirects.first().redirect_link, "http://www.test.com/") - self.assertIsNone(redirects.first().site) + self.assertEqual(redirect.redirect_link, "http://www.test.com/") + self.assertIsNone(redirect.site) + + # Check that the action log is marked as "created" + log_entry = log_registry.get_logs_for_instance(redirect).first() + self.assertEqual(log_entry.action, "wagtail.create") def test_add_with_site(self): localhost = Site.objects.get(hostname="localhost") diff --git a/wagtail/contrib/redirects/views.py b/wagtail/contrib/redirects/views.py index e6c0629c8f..f15e0173c3 100644 --- a/wagtail/contrib/redirects/views.py +++ b/wagtail/contrib/redirects/views.py @@ -179,7 +179,7 @@ def add(request): if form.is_valid(): with transaction.atomic(): theredirect = form.save() - log(instance=theredirect, action="wagtail.edit") + log(instance=theredirect, action="wagtail.create") messages.success( request,