Move get_valid_next_url_from_request to wagtail.admin.utils

pull/9649/head
Sage Abdullah 2022-11-15 09:56:12 +00:00 zatwierdzone przez Matt Westcott
rodzic 44933d06c4
commit fd8ffba638
13 zmienionych plików z 23 dodań i 22 usunięć

Wyświetl plik

@ -31,9 +31,8 @@ from wagtail.admin.navigation import get_explorable_root_page
from wagtail.admin.search import admin_search_areas
from wagtail.admin.staticfiles import versioned_static as versioned_static_func
from wagtail.admin.ui import sidebar
from wagtail.admin.utils import get_admin_base_url
from wagtail.admin.utils import get_admin_base_url, get_valid_next_url_from_request
from wagtail.admin.views.bulk_action.registry import bulk_action_registry
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.widgets import ButtonWithDropdown, PageListingButton
from wagtail.coreutils import camelcase_to_underscore
from wagtail.coreutils import cautious_slugify as _cautious_slugify

Wyświetl plik

@ -1,6 +1,7 @@
from warnings import warn
from django.conf import settings
from django.utils.http import url_has_allowed_host_and_scheme
from wagtail.utils.deprecation import RemovedInWagtail50Warning
@ -20,3 +21,12 @@ def get_admin_base_url():
admin_base_url = settings.BASE_URL
return admin_base_url
def get_valid_next_url_from_request(request):
next_url = request.POST.get("next") or request.GET.get("next")
if not next_url or not url_has_allowed_host_and_scheme(
url=next_url, allowed_hosts={request.get_host()}
):
return ""
return next_url

Wyświetl plik

@ -7,7 +7,7 @@ from django.views.generic import FormView
from wagtail import hooks
from wagtail.admin import messages
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
class BulkAction(ABC, FormView):

Wyświetl plik

@ -7,7 +7,7 @@ from django.utils.translation import gettext as _
from wagtail import hooks
from wagtail.actions.convert_alias import ConvertAliasPageAction
from wagtail.admin import messages
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.models import Page

Wyświetl plik

@ -8,7 +8,7 @@ from wagtail.actions.create_alias import CreatePageAliasAction
from wagtail.admin import messages
from wagtail.admin.auth import user_has_any_page_permission, user_passes_test
from wagtail.admin.forms.pages import CopyForm
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.models import Page

Wyświetl plik

@ -14,8 +14,8 @@ from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
from wagtail.admin import messages, signals
from wagtail.admin.action_menu import PageActionMenu
from wagtail.admin.ui.side_panels import PageSidePanels
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.admin.views.generic import HookResponseMixin
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.models import Locale, Page, PageSubscription, UserPagePermissionsProxy

Wyświetl plik

@ -8,7 +8,7 @@ from django.utils.translation import gettext as _
from wagtail import hooks
from wagtail.actions.delete_page import DeletePageAction
from wagtail.admin import messages
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.models import Page

Wyświetl plik

@ -18,8 +18,8 @@ from wagtail.admin import messages
from wagtail.admin.action_menu import PageActionMenu
from wagtail.admin.mail import send_notification
from wagtail.admin.ui.side_panels import PageSidePanels
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.admin.views.generic import HookResponseMixin
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.exceptions import PageClassNotFoundError
from wagtail.locks import BasicLock, ScheduledForPublishLock
from wagtail.models import (

Wyświetl plik

@ -12,12 +12,12 @@ 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,
)
from wagtail.admin.views.generic.preview import PreviewRevision
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.models import Page, UserPagePermissionsProxy

Wyświetl plik

@ -6,8 +6,8 @@ from django.utils.translation import gettext_lazy as _
from wagtail import hooks
from wagtail.actions.unpublish_page import UnpublishPageAction
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.admin.views.generic.models import UnpublishView
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.models import Page, UserPagePermissionsProxy

Wyświetl plik

@ -1,10 +1,2 @@
from django.utils.http import url_has_allowed_host_and_scheme
def get_valid_next_url_from_request(request):
next_url = request.POST.get("next") or request.GET.get("next")
if not next_url or not url_has_allowed_host_and_scheme(
url=next_url, allowed_hosts={request.get_host()}
):
return ""
return next_url
# Retain backwards compatibility for imports
from wagtail.admin.utils import get_valid_next_url_from_request # noqa

Wyświetl plik

@ -15,7 +15,7 @@ from wagtail.admin.admin_url_finder import AdminURLFinder
from wagtail.admin.auth import PermissionPolicyChecker
from wagtail.admin.forms.search import SearchForm
from wagtail.admin.models import popular_tags_for_model
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.documents import get_document_model
from wagtail.documents.forms import get_document_form
from wagtail.documents.permissions import permission_policy

Wyświetl plik

@ -18,7 +18,7 @@ from wagtail.admin.admin_url_finder import AdminURLFinder
from wagtail.admin.auth import PermissionPolicyChecker
from wagtail.admin.forms.search import SearchForm
from wagtail.admin.models import popular_tags_for_model
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.images import get_image_model
from wagtail.images.exceptions import InvalidFilterSpecError
from wagtail.images.forms import URLGeneratorForm, get_image_form