Fix page history with deleted user

pull/7520/head
Dan Braghis 2021-09-17 17:17:42 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic e565ecb618
commit a87acf5b17
4 zmienionych plików z 24 dodań i 5 usunięć

Wyświetl plik

@ -39,6 +39,7 @@ Changelog
* Fix: Ensure admin tab JS events are handled on page load (Andrew Stone)
* Fix: `EmailNotificationMixin` and `send_notification` should only send emails to active users (Bryan Williams)
* Fix: Disable Task confirmation now shows the correct value for quantity of tasks in progress (LB Johnston)
* Fix: Page history now works correctly when it contains changes by a deleted user (Dan Braghis)
2.14.1 (12.08.2021)

Wyświetl plik

@ -54,6 +54,7 @@ Bug fixes
* Ensure admin tab JS events are handled on page load (Andrew Stone)
* `EmailNotificationMixin` and `send_notification` should only send emails to active users (Bryan Williams)
* Disable Task confirmation now shows the correct value for quantity of tasks in progress (LB Johnston)
* Page history now works correctly when it contains changes by a deleted user (Dan Braghis)
Upgrade considerations
======================

Wyświetl plik

@ -151,6 +151,24 @@ class TestAuditLogAdmin(TestCase, WagtailTestUtils):
self.assertContains(response, 'About', 3) # create, save draft, delete
self.assertContains(response, 'Deleted', 2)
def test_history_with_deleted_user(self):
self._update_page(self.hello_page)
expected_deleted_string = f"user {self.editor.pk} (deleted)"
self.editor.delete()
self.login(user=self.administrator)
# check page history
response = self.client.get(
reverse('wagtailadmin_pages:history', kwargs={'page_id': self.hello_page.id})
)
self.assertContains(response, expected_deleted_string)
# check site history
response = self.client.get(reverse('wagtailadmin_reports:site_history'))
self.assertContains(response, expected_deleted_string)
def test_edit_form_has_history_link(self):
self.hello_page.save_revision()
self.login(user=self.editor)

Wyświetl plik

@ -135,11 +135,10 @@ class BaseLogEntry(models.Model):
Defaults to 'system' when none is provided
"""
if self.user_id:
try:
user = self.user
except self._meta.get_field('user').related_model.DoesNotExist:
# User has been deleted
return _('user %(id)d (deleted)') % {'id': self.user_id}
user = self.user
if user is None:
# User has been deleted. Using a string placeholder as the user id could be non-numeric
return _('user %(id)s (deleted)') % {'id': self.user_id}
try:
full_name = user.get_full_name().strip()