0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Allow scheduled publishing to happen when the initial editor did not have publish permission

Fixes #8585
This commit is contained in:
Matt Westcott 2022-06-14 15:35:20 +02:00
parent cb43536f07
commit b834c7aec7
2 changed files with 59 additions and 2 deletions

View File

@ -112,4 +112,4 @@ class Command(BaseCommand):
for rp in revs_for_publishing:
# just run publish for the revision -- since the approved go
# live datetime is before now it will make the page live
rp.publish(user=rp.user, log_action="wagtail.publish.scheduled")
rp.publish(log_action="wagtail.publish.scheduled")

View File

@ -3,6 +3,7 @@ from io import StringIO
from unittest import mock
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core import management
from django.db import models
from django.test import TestCase
@ -11,6 +12,7 @@ from django.utils import timezone
from wagtail.models import Collection, Page, PageLogEntry, Revision
from wagtail.signals import page_published, page_unpublished
from wagtail.test.testapp.models import EventPage, SecretPage, SimplePage
from wagtail.test.utils import WagtailTestUtils
class TestFixTreeCommand(TestCase):
@ -160,7 +162,9 @@ class TestSetUrlPathsCommand(TestCase):
self.run_command()
class TestPublishScheduledPagesCommand(TestCase):
class TestPublishScheduledPagesCommand(WagtailTestUtils, TestCase):
fixtures = ["test.json"]
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
@ -213,6 +217,59 @@ class TestPublishScheduledPagesCommand(TestCase):
self.assertEqual(signal_page[0], page)
self.assertEqual(signal_page[0], signal_page[0].specific)
def test_go_live_page_created_by_editor_will_be_published(self):
# Connect a mock signal handler to page_published signal
signal_fired = [False]
signal_page = [None]
editor = self.create_user("ed")
editor.groups.add(Group.objects.get(name="Site-wide editors"))
def page_published_handler(sender, instance, **kwargs):
signal_fired[0] = True
signal_page[0] = instance
page_published.connect(page_published_handler)
page = SimplePage(
title="Hello world!",
slug="hello-world",
content="hello",
live=False,
has_unpublished_changes=True,
go_live_at=timezone.now() - timedelta(days=1),
)
self.root_page.add_child(instance=page)
page.save_revision(
user=editor, approved_go_live_at=timezone.now() - timedelta(days=1)
)
p = Page.objects.get(slug="hello-world")
self.assertFalse(p.live)
self.assertTrue(
Revision.page_revisions.filter(object_id=p.id)
.exclude(approved_go_live_at__isnull=True)
.exists()
)
management.call_command("publish_scheduled_pages")
p = Page.objects.get(slug="hello-world")
self.assertTrue(p.live)
self.assertTrue(p.first_published_at)
self.assertFalse(p.has_unpublished_changes)
self.assertFalse(
Revision.page_revisions.filter(object_id=p.id)
.exclude(approved_go_live_at__isnull=True)
.exists()
)
# Check that the page_published signal was fired
self.assertTrue(signal_fired[0])
self.assertEqual(signal_page[0], page)
self.assertEqual(signal_page[0], signal_page[0].specific)
def test_go_live_when_newer_revision_exists(self):
page = SimplePage(
title="Hello world!",