From e7595ab91dc41c25e3b2c0e5354648593c6a6207 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Thu, 28 Sep 2023 15:23:27 +0100 Subject: [PATCH] Raise warning if there are revisions for moderation --- wagtail/admin/tests/test_moderation_list.py | 17 ++++++++++++++++- wagtail/admin/views/home.py | 14 +++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/wagtail/admin/tests/test_moderation_list.py b/wagtail/admin/tests/test_moderation_list.py index 27c83be91b..3264341a75 100644 --- a/wagtail/admin/tests/test_moderation_list.py +++ b/wagtail/admin/tests/test_moderation_list.py @@ -5,11 +5,18 @@ from django.urls import reverse from wagtail.models import GroupPagePermission, Page from wagtail.test.testapp.models import SimplePage from wagtail.test.utils import WagtailTestUtils +from wagtail.utils.deprecation import RemovedInWagtail60Warning class TestModerationList(WagtailTestUtils, TestCase): """Test moderation list rendered by `wagtailadmin_home` view""" + # RemovedInWagtail60Warning + # Remove this test class when the deprecation period for the legacy + # moderation system ends. + # For workflows, this has been covered in + # wagtail.admin.tests.test_workflows.TestDashboardWithPages + def setUp(self): # Create a submitter submitter = self.create_user( @@ -70,7 +77,15 @@ class TestModerationList(WagtailTestUtils, TestCase): self.login(moderator) def get(self): - return self.client.get(reverse("wagtailadmin_home")) + with self.assertWarnsMessage( + RemovedInWagtail60Warning, + "You have pages undergoing moderation in the legacy moderation system. " + "Complete the moderation of these pages before upgrading Wagtail. " + "Support for the legacy moderation system will be completely removed " + "in a future release. For more details, refer to " + "https://docs.wagtail.org/en/stable/releases/2.10.html#move-to-new-configurable-moderation-system-workflow", + ): + return self.client.get(reverse("wagtailadmin_home")) def test_edit_page(self): # Login as moderator diff --git a/wagtail/admin/views/home.py b/wagtail/admin/views/home.py index f527ff2817..6beda9c42a 100644 --- a/wagtail/admin/views/home.py +++ b/wagtail/admin/views/home.py @@ -1,5 +1,6 @@ import itertools import re +import warnings from typing import Any, Mapping, Union from django.conf import settings @@ -27,6 +28,7 @@ from wagtail.models import ( get_default_page_content_type, ) from wagtail.permission_policies.pages import PagePermissionPolicy +from wagtail.utils.deprecation import RemovedInWagtail60Warning User = get_user_model() @@ -100,12 +102,22 @@ class PagesForModerationPanel(Component): def get_context_data(self, parent_context): request = parent_context["request"] context = super().get_context_data(parent_context) - context["page_revisions_for_moderation"] = ( + revisions = ( PagePermissionPolicy() .revisions_for_moderation(request.user) .select_related("user") .order_by("-created_at") ) + if revisions: + warnings.warn( + "You have pages undergoing moderation in the legacy moderation system. " + "Complete the moderation of these pages before upgrading Wagtail. " + "Support for the legacy moderation system will be completely removed " + "in a future release. For more details, refer to " + "https://docs.wagtail.org/en/stable/releases/2.10.html#move-to-new-configurable-moderation-system-workflow", + RemovedInWagtail60Warning, + ) + context["page_revisions_for_moderation"] = revisions context["request"] = request context["csrf_token"] = parent_context["csrf_token"] return context