kopia lustrzana https://github.com/wagtail/wagtail
Validate the slug field in CopyForm against invalid characters
rodzic
e1d1fc917f
commit
0f8e3cbe57
|
@ -85,7 +85,7 @@ class CopyForm(forms.Form):
|
||||||
super(CopyForm, self).__init__(*args, **kwargs)
|
super(CopyForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.fields['new_title'] = forms.CharField(initial=self.page.title)
|
self.fields['new_title'] = forms.CharField(initial=self.page.title)
|
||||||
self.fields['new_slug'] = forms.CharField(initial=self.page.slug)
|
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug)
|
||||||
|
|
||||||
copy_subpages = forms.BooleanField(required=False, initial=True)
|
copy_subpages = forms.BooleanField(required=False, initial=True)
|
||||||
publish_copies = forms.BooleanField(required=False, initial=True)
|
publish_copies = forms.BooleanField(required=False, initial=True)
|
||||||
|
|
|
@ -1127,6 +1127,21 @@ class TestPageCopy(TestCase, WagtailTestUtils):
|
||||||
# Check that a form error was raised
|
# Check that a form error was raised
|
||||||
self.assertFormError(response, 'form', 'new_slug', "This slug is already in use")
|
self.assertFormError(response, 'form', 'new_slug', "This slug is already in use")
|
||||||
|
|
||||||
|
def test_page_copy_post_invalid_slug(self):
|
||||||
|
# Attempt to copy the page but set an invalid slug string
|
||||||
|
post_data = {
|
||||||
|
'new_title': "Hello world 2",
|
||||||
|
'new_slug': 'hello world!',
|
||||||
|
'copy_subpages': False,
|
||||||
|
}
|
||||||
|
response = self.client.post(reverse('wagtailadmin_pages_copy', args=(self.test_page.id, )), post_data)
|
||||||
|
|
||||||
|
# Should not be redirected (as the save should fail)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Check that a form error was raised
|
||||||
|
self.assertFormError(response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.")
|
||||||
|
|
||||||
def test_page_copy_no_publish_permission(self):
|
def test_page_copy_no_publish_permission(self):
|
||||||
# Turn user into an editor who can add pages but not publish them
|
# Turn user into an editor who can add pages but not publish them
|
||||||
self.user.is_superuser = False
|
self.user.is_superuser = False
|
||||||
|
|
Ładowanie…
Reference in New Issue