Add `wagtail.reorder` audit log action

This adds a special audit message for reordering pages.

Previously, reordering pages under the same parent would show the
slighly misleading message that the page was moved to the same parent.
A special page reordered message would be more appropiate in this case.
pull/6967/head
Storm Heg 2021-03-03 21:07:09 +01:00
rodzic 520fa23ced
commit 1ff679f861
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A13DE630DD3AA5B6
6 zmienionych plików z 32 dodań i 1 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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': {

Wyświetl plik

@ -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(