Use next parameter for redirect response in generic RevisionsUnscheduleView

pull/9649/head
Sage Abdullah 2022-11-15 10:03:19 +00:00 zatwierdzone przez Matt Westcott
rodzic fd8ffba638
commit a886e26993
3 zmienionych plików z 34 dodań i 7 usunięć

Wyświetl plik

@ -538,6 +538,35 @@ class TestRevisionsUnschedule(TestCase, WagtailTestUtils):
).approved_go_live_at
)
def test_unschedule_view_post_with_next_url(self):
"""
This tests that the redirect response follows the "next" parameter
"""
unschedule_url = reverse(
"wagtailadmin_pages:revisions_unschedule",
args=(self.christmas_event.id, self.this_christmas_revision.id),
)
edit_url = reverse("wagtailadmin_pages:edit", args=(self.christmas_event.id,))
# Post to the unschedule page
response = self.client.post(f"{unschedule_url}?next={edit_url}")
# Should be redirected to edit page
self.assertRedirects(response, edit_url)
# Check that the page has no approved_schedule
self.assertFalse(
EventPage.objects.get(id=self.christmas_event.id).approved_schedule
)
# Check that the approved_go_live_at has been cleared from the revision
self.assertIsNone(
self.christmas_event.revisions.get(
id=self.this_christmas_revision.id
).approved_go_live_at
)
class TestRevisionsUnscheduleForUnpublishedPages(TestCase, WagtailTestUtils):
fixtures = ["test.json"]

Wyświetl plik

@ -24,6 +24,7 @@ from wagtail.admin.forms.search import SearchForm
from wagtail.admin.panels import get_edit_handler
from wagtail.admin.templatetags.wagtailadmin_tags import user_display_name
from wagtail.admin.ui.tables import Column, Table, TitleColumn, UpdatedAtColumn
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.log_actions import log
from wagtail.log_actions import registry as log_registry
from wagtail.models import DraftStateMixin, RevisionMixin
@ -1018,6 +1019,10 @@ class RevisionsUnscheduleView(TemplateView):
]
def get_next_url(self):
next_url = get_valid_next_url_from_request(self.request)
if next_url:
return next_url
if not self.history_url_name:
raise ImproperlyConfigured(
"Subclasses of wagtail.admin.views.generic.models.RevisionsUnscheduleView "

Wyświetl plik

@ -12,7 +12,6 @@ from wagtail.admin import messages
from wagtail.admin.action_menu import PageActionMenu
from wagtail.admin.auth import user_has_any_page_permission, user_passes_test
from wagtail.admin.ui.side_panels import PageSidePanels
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.admin.views.generic.models import (
RevisionsCompareView,
RevisionsUnscheduleView,
@ -159,9 +158,3 @@ class RevisionsUnschedule(RevisionsUnscheduleView):
def get_object_display_title(self):
return self.object.get_admin_display_title()
def get_success_url(self):
next_url = get_valid_next_url_from_request(self.request)
if next_url:
return next_url
return super().get_success_url()