Publish aliases when the source page is published

Fixes # 6749

Aliases are currently not being published if they were created in draft
pull/7887/head
Karl Hobley 2021-02-03 10:10:33 +00:00 zatwierdzone przez Matt Westcott
rodzic 0827c8afbd
commit 0d8d9f56b5
2 zmienionych plików z 43 dodań i 0 usunięć

Wyświetl plik

@ -1416,6 +1416,10 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
# Copy field content
alias_updated = alias.with_content_json(_content_json)
# Publish the alias if it's currently in draft
alias_updated.live = True
alias_updated.has_unpublished_changes = False
# Copy child relations
child_object_map = specific_self.copy_all_child_relations(target=alias_updated, exclude=exclude_fields)

Wyświetl plik

@ -1972,6 +1972,45 @@ class TestUpdateAliases(TestCase):
self.assertTrue(PageLogEntry.objects.filter(page=alias, action='wagtail.publish').exists())
self.assertTrue(PageLogEntry.objects.filter(page=alias_alias, action='wagtail.publish').exists())
def test_update_aliases_publishes_drafts(self):
event_page = EventPage.objects.get(url_path='/home/events/christmas/')
# Unpublish the event page so that the aliases will be created in draft
event_page.live = False
event_page.has_unpublished_changes = True
event_page.save(clean=False)
alias = event_page.create_alias(update_slug='new-event-page')
alias_alias = alias.create_alias(update_slug='new-event-page-2')
self.assertFalse(alias.live)
self.assertFalse(alias_alias.live)
# Publish the event page
event_page.live = True
event_page.has_unpublished_changes = False
event_page.save(clean=False)
# Nothing should've happened yet
alias.refresh_from_db()
alias_alias.refresh_from_db()
self.assertFalse(alias.live)
self.assertFalse(alias_alias.live)
PageLogEntry.objects.all().delete()
event_page.update_aliases()
# Check that the aliases have been updated
alias.refresh_from_db()
alias_alias.refresh_from_db()
self.assertTrue(alias.live)
self.assertTrue(alias_alias.live)
# Check log entries were created
self.assertTrue(PageLogEntry.objects.filter(page=alias, action='wagtail.publish').exists())
self.assertTrue(PageLogEntry.objects.filter(page=alias_alias, action='wagtail.publish').exists())
class TestCopyForTranslation(TestCase):
fixtures = ['test.json']