mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-30 11:34:49 +00:00
Don't include protected pages in sitemap. Fixes #407
This commit is contained in:
parent
5cead3c40a
commit
7d4f4c2edd
2 changed files with 13 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ class Sitemap(object):
|
|||
self.site = site
|
||||
|
||||
def get_pages(self):
|
||||
return self.site.root_page.get_descendants(inclusive=True).live().order_by('path')
|
||||
return self.site.root_page.get_descendants(inclusive=True).live().public().order_by('path')
|
||||
|
||||
def get_urls(self):
|
||||
for page in self.get_pages():
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from django.core.cache import cache
|
||||
|
||||
from wagtail.wagtailcore.models import Page, Site
|
||||
from wagtail.wagtailcore.models import Page, PageViewRestriction, Site
|
||||
from wagtail.tests.models import SimplePage
|
||||
|
||||
from .sitemap_generator import Sitemap
|
||||
|
|
@ -23,6 +23,13 @@ class TestSitemapGenerator(TestCase):
|
|||
live=False,
|
||||
))
|
||||
|
||||
self.protected_child_page = self.home_page.add_child(instance=SimplePage(
|
||||
title="Protected",
|
||||
slug='protected',
|
||||
live=True,
|
||||
))
|
||||
PageViewRestriction.objects.create(page=self.protected_child_page, password='hello')
|
||||
|
||||
self.site = Site.objects.get(is_default_site=True)
|
||||
|
||||
def test_get_pages(self):
|
||||
|
|
@ -31,6 +38,7 @@ class TestSitemapGenerator(TestCase):
|
|||
|
||||
self.assertIn(self.child_page.page_ptr, pages)
|
||||
self.assertNotIn(self.unpublished_child_page.page_ptr, pages)
|
||||
self.assertNotIn(self.protected_child_page.page_ptr, pages)
|
||||
|
||||
def test_get_urls(self):
|
||||
sitemap = Sitemap(self.site)
|
||||
|
|
@ -49,6 +57,9 @@ class TestSitemapGenerator(TestCase):
|
|||
# Make sure the unpublished page didn't make it into the xml
|
||||
self.assertNotIn('/unpublished/', xml)
|
||||
|
||||
# Make sure the protected page didn't make it into the xml
|
||||
self.assertNotIn('/protected/', xml)
|
||||
|
||||
|
||||
class TestSitemapView(TestCase):
|
||||
def test_sitemap_view(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue