kopia lustrzana https://github.com/wagtail/wagtail
fix: modify get_full_url to omit adding base_url in inaplicable cases (#10291)
Fixes #10285pull/10349/head
rodzic
cc223daa17
commit
0447b259c7
|
@ -76,6 +76,7 @@ Changelog
|
|||
* Fix: Avoid showing scrollbars in the block picker unless necessary (Babitha Kumari)
|
||||
* Fix: Always show Add buttons, guide lines, Move up/down, Duplicate, Delete; in StreamField and Inline Panel (Thibaud Colas)
|
||||
* Fix: Make admin JS i18n endpoint accessible to non-authenticated users (Matt Westcott)
|
||||
* Fix: Fix incorrect API serialisation for document `download_url` when `WAGTAILDOCS_SERVE_METHOD` is `direct` (Swojak-A)
|
||||
* Autosize text area field will now correctly resize when switching between comments toggle states (Suyash Srivastava)
|
||||
* Docs: Add code block to make it easier to understand contribution docs (Suyash Singh)
|
||||
* Docs: Add new "Icons" page for icons customisation and reuse across the admin interface (Coen van der Kamp, Thibaud Colas)
|
||||
|
|
|
@ -706,6 +706,7 @@ Contributors
|
|||
* Mansi Gundre
|
||||
* Hanoon
|
||||
* Steve Steinwand
|
||||
* Swojak-A
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -118,6 +118,7 @@ Those improvements were implemented by Albina Starykova as part of an [Outreachy
|
|||
* Always show Add buttons, guide lines, Move up/down, Duplicate, Delete; in StreamField and Inline Panel (Thibaud Colas)
|
||||
* Make admin JS i18n endpoint accessible to non-authenticated users (Matt Westcott)
|
||||
* Autosize text area field will now correctly resize when switching between comments toggle states (Suyash Srivastava)
|
||||
* Fix incorrect API serialisation for document `download_url` when `WAGTAILDOCS_SERVE_METHOD` is `direct` (Swojak-A)
|
||||
|
||||
### Documentation
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ def get_base_url(request=None):
|
|||
|
||||
|
||||
def get_full_url(request, path):
|
||||
if path.startswith(("http://", "https://")):
|
||||
return path
|
||||
base_url = get_base_url(request) or ""
|
||||
return base_url + path
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
from django.core.files.base import ContentFile
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from wagtail.documents import models
|
||||
|
||||
|
||||
class TestCorrectDownloadUrlSerialization(TestCase):
|
||||
|
||||
"""Test asserts that in case of both `redirect` and `direct`
|
||||
WAGTAILDOCS_SERVE_METHOD settings `download_url` field
|
||||
is correctly serialized by DocumentDownloadUrlField."""
|
||||
|
||||
def setUp(self):
|
||||
self.document = models.Document(title="Test document", file_hash="123456")
|
||||
self.document.file.save("example.doc", ContentFile("A boring example document"))
|
||||
|
||||
def tearDown(self):
|
||||
# delete the FieldFile directly because the TestCase does not commit
|
||||
# transactions to trigger transaction.on_commit() in the signal handler
|
||||
self.document.file.delete()
|
||||
|
||||
def get_response(self, document_id, **params):
|
||||
return self.client.get(
|
||||
reverse("wagtailapi_v2:documents:detail", args=(document_id,)), params
|
||||
)
|
||||
|
||||
@override_settings(
|
||||
WAGTAILDOCS_SERVE_METHOD="redirect",
|
||||
DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage",
|
||||
WAGTAILAPI_BASE_URL="http://example.com/",
|
||||
)
|
||||
def test_serializer_wagtaildocs_serve_redirect(self):
|
||||
response = self.get_response(self.document.id)
|
||||
data = response.json()
|
||||
self.assertIn("meta", data)
|
||||
meta = data["meta"]
|
||||
self.assertIn("download_url", meta)
|
||||
download_url = meta["download_url"]
|
||||
expected_url = "http://example.com/documents/%d/example.doc" % self.document.pk
|
||||
self.assertEqual(download_url, expected_url)
|
||||
|
||||
@override_settings(
|
||||
WAGTAILDOCS_SERVE_METHOD="direct",
|
||||
DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage",
|
||||
MEDIA_URL="http://remotestorage.com/media/",
|
||||
WAGTAILAPI_BASE_URL="http://example.com/",
|
||||
)
|
||||
def test_serializer_wagtaildocs_serve_direct(self):
|
||||
response = self.get_response(self.document.id)
|
||||
data = response.json()
|
||||
self.assertIn("meta", data)
|
||||
meta = data["meta"]
|
||||
self.assertIn("download_url", meta)
|
||||
download_url = meta["download_url"]
|
||||
self.assertEqual(
|
||||
download_url, "http://remotestorage.com/media/documents/example.doc"
|
||||
)
|
Ładowanie…
Reference in New Issue