diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 34e4105a85..f15e687886 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -14,6 +14,7 @@ Changelog * Utilize `PageQuerySet.defer_streamfields()` to improve efficiency in a few key places (Andy Babic) * Switch ``register_setting``, ``register_settings_menu_item`` to use SVG icons (Thibaud Colas) * Add support to SVG icons for ``SearchArea`` subclasses in ``register_admin_search_area`` (Thibaud Colas) + * Add `wagtail.reorder` page audit log action (Storm Heg) * `get_settings` template tag now supports specifying the variable name with `{% get_settings as var %}` (Samir Shah) * Fix: StreamField required status is now consistently handled by the `blank` keyword argument (Matt Westcott) * Fix: Show 'required' asterisks for blocks inside required StreamFields (Matt Westcott) diff --git a/docs/advanced_topics/audit_log.rst b/docs/advanced_topics/audit_log.rst index 6347c60ec0..72e17ba451 100644 --- a/docs/advanced_topics/audit_log.rst +++ b/docs/advanced_topics/audit_log.rst @@ -72,6 +72,7 @@ Action Notes ``wagtail.revert`` The page was reverted to a previous draft ``wagtail.copy`` The page was copied to a new location ``wagtail.move`` The page was moved to a new location +``wagtail.reorder`` The order of the page under it's parent was changed ``wagtail.view_restriction.create`` The page was restricted ``wagtail.view_restriction.edit`` The page restrictions were updated ``wagtail.view_restriction.delete`` The page restrictions were removed diff --git a/docs/releases/2.13.rst b/docs/releases/2.13.rst index f73cbe235e..0b7dc645f7 100644 --- a/docs/releases/2.13.rst +++ b/docs/releases/2.13.rst @@ -31,6 +31,7 @@ Other features * Update ``PageQueryset.specific(defer=True)`` to only perform a single database query (Andy Babic) * Switched ``register_setting``, ``register_settings_menu_item`` to use SVG icons (Thibaud Colas) * Add support to SVG icons for ``SearchArea`` subclasses in ``register_admin_search_area`` (Thibaud Colas) +* Add specialized ``wagtail.reorder`` page audit log action. This was previously covered by the ``wagtail.move`` action (Storm Heg) * ``get_settings`` template tag now supports specifying the variable name with ``{% get_settings as var %}`` (Samir Shah) Bug fixes diff --git a/wagtail/admin/wagtail_hooks.py b/wagtail/admin/wagtail_hooks.py index 03ebda616b..388afeae0c 100644 --- a/wagtail/admin/wagtail_hooks.py +++ b/wagtail/admin/wagtail_hooks.py @@ -866,6 +866,14 @@ def register_core_log_actions(actions): except KeyError: return _('Moved') + def reorder_message(data): + try: + return _("Reordered under '%(parent)s'") % { + 'parent': data['destination']['title'], + } + except KeyError: + return _('Reordered') + def schedule_publish_message(data): try: if data['revision']['has_live_version']: @@ -935,6 +943,7 @@ def register_core_log_actions(actions): actions.register_action('wagtail.create_alias', _('Create alias'), create_alias_message) actions.register_action('wagtail.convert_alias', _('Convert alias into regular page'), convert_alias_message) actions.register_action('wagtail.move', _('Move'), move_message) + actions.register_action('wagtail.reorder', _('Reorder'), reorder_message) actions.register_action('wagtail.publish.schedule', _("Schedule publication"), schedule_publish_message) actions.register_action('wagtail.schedule.cancel', _("Unschedule publication"), unschedule_publish_message) actions.register_action('wagtail.view_restriction.create', _("Add view restrictions"), add_view_restriction) diff --git a/wagtail/core/models.py b/wagtail/core/models.py index c00f939e75..39f35e81a2 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -2062,7 +2062,8 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): # Log PageLogEntry.objects.log_action( instance=self, - action='wagtail.move', + # Check if page was reordered (reordering doesn't change the parent) + action='wagtail.reorder' if parent_before.id == target.id else 'wagtail.move', user=user, data={ 'source': { diff --git a/wagtail/core/tests/test_audit_log.py b/wagtail/core/tests/test_audit_log.py index b4e0d662cb..8ba71be5e1 100644 --- a/wagtail/core/tests/test_audit_log.py +++ b/wagtail/core/tests/test_audit_log.py @@ -185,6 +185,23 @@ class TestAuditLog(TestCase): ['wagtail.publish', 'wagtail.copy', 'wagtail.create'] ) + def test_page_reorder(self): + section_1 = self.root_page.add_child( + instance=SimplePage(title="Child 1", slug="child-1", content="hello") + ) + self.root_page.add_child( + instance=SimplePage(title="Child 2", slug="child-2", content="hello") + ) + + user = get_user_model().objects.first() + + # Reorder section 1 to be the last page under root_page. + # This should log as `wagtail.reorder` because the page was moved under the same parent page + section_1.move(self.root_page, user=user, pos="last-child") + + self.assertEqual(PageLogEntry.objects.filter(action='wagtail.reorder', user=user).count(), 1) + self.assertEqual(PageLogEntry.objects.filter(action='wagtail.move', user=user).count(), 0) + def test_page_move(self): section = self.root_page.add_child( instance=SimplePage(title="About us", slug="about", content="hello") @@ -193,6 +210,7 @@ class TestAuditLog(TestCase): section.move(self.home_page, user=user) self.assertEqual(PageLogEntry.objects.filter(action='wagtail.move', user=user).count(), 1) + self.assertEqual(PageLogEntry.objects.filter(action='wagtail.reorder', user=user).count(), 0) def test_page_delete(self): self.home_page.add_child(