mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 16:24:49 +00:00
Make can_add_subpage and can_publish_subpage permission checks return False for page models that disallow subpages; this ensures that 'add child page' links are not shown
This commit is contained in:
parent
a4b60715b9
commit
6bfe82f5e5
2 changed files with 33 additions and 6 deletions
|
|
@ -703,22 +703,44 @@ class TestSubpageBusinessRules(TestCase, WagtailTestUtils):
|
|||
self.login()
|
||||
|
||||
def test_standard_subpage(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.standard_index.id, )))
|
||||
add_subpage_url = reverse('wagtailadmin_pages_add_subpage', args=(self.standard_index.id, ))
|
||||
|
||||
# explorer should contain a link to 'add child page'
|
||||
response = self.client.get(reverse('wagtailadmin_explore', args=(self.standard_index.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, add_subpage_url)
|
||||
|
||||
# add_subpage should give us the full set of page types to choose
|
||||
response = self.client.get(add_subpage_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'Standard Child')
|
||||
self.assertContains(response, 'Business Child')
|
||||
|
||||
def test_business_subpage(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.business_index.id, )))
|
||||
add_subpage_url = reverse('wagtailadmin_pages_add_subpage', args=(self.business_index.id, ))
|
||||
|
||||
# explorer should contain a link to 'add child page'
|
||||
response = self.client.get(reverse('wagtailadmin_explore', args=(self.business_index.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, add_subpage_url)
|
||||
|
||||
# add_subpage should give us a cut-down set of page types to choose
|
||||
response = self.client.get(add_subpage_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'Standard Child')
|
||||
self.assertContains(response, 'Business Child')
|
||||
|
||||
def test_business_child_subpage(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.business_child.id, )))
|
||||
add_subpage_url = reverse('wagtailadmin_pages_add_subpage', args=(self.business_child.id, ))
|
||||
|
||||
# explorer should not contain a link to 'add child page', as this page doesn't accept subpages
|
||||
response = self.client.get(reverse('wagtailadmin_explore', args=(self.business_child.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'Standard Child')
|
||||
self.assertEqual(0, len(response.context['page_types']))
|
||||
self.assertNotContains(response, add_subpage_url)
|
||||
|
||||
# this also means that fetching add_subpage is blocked at the permission-check level
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.business_child.id, )))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_cannot_add_invalid_subpage_type(self):
|
||||
# cannot add SimplePage as a child of BusinessIndex, as SimplePage is not present in subpage_types
|
||||
|
|
|
|||
|
|
@ -843,6 +843,8 @@ class PagePermissionTester(object):
|
|||
def can_add_subpage(self):
|
||||
if not self.user.is_active:
|
||||
return False
|
||||
if not self.page.specific_class.clean_subpage_types(): # this page model has an empty subpage_types list, so no subpages are allowed
|
||||
return False
|
||||
return self.user.is_superuser or ('add' in self.permissions)
|
||||
|
||||
def can_edit(self):
|
||||
|
|
@ -897,10 +899,13 @@ class PagePermissionTester(object):
|
|||
"""
|
||||
Niggly special case for creating and publishing a page in one go.
|
||||
Differs from can_publish in that we want to be able to publish subpages of root, but not
|
||||
to be able to publish root itself
|
||||
to be able to publish root itself. (Also, can_publish_subpage returns false if the page
|
||||
does not allow subpages at all.)
|
||||
"""
|
||||
if not self.user.is_active:
|
||||
return False
|
||||
if not self.page.specific_class.clean_subpage_types(): # this page model has an empty subpage_types list, so no subpages are allowed
|
||||
return False
|
||||
|
||||
return self.user.is_superuser or ('publish' in self.permissions)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue