Skip to content

Commit 710c7d9

Browse files
authored
Do not return restricted pages in cmsPages (#4222)
1 parent f3191a4 commit 710c7d9

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

backend/api/cms/page/queries/cms_pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def cms_pages(hostname: str, language: str) -> list[GenericPage]:
1515
return [
1616
GenericPage.from_model(page)
1717
for page in GenericPageModel.objects.in_site(site).filter(
18-
locale__language_code=language, live=True
18+
locale__language_code=language, live=True, view_restrictions__isnull=True
1919
)
2020
]

backend/api/cms/tests/page/queries/test_cms_pages.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from wagtail.models import PageViewRestriction
12
import pytest
23
from api.cms.tests.factories import GenericPageFactory, SiteFactory
34

@@ -48,6 +49,49 @@ def test_pages(graphql_client, locale):
4849
}
4950

5051

52+
def test_restricted_pages_are_not_returned(graphql_client, locale):
53+
parent = GenericPageFactory()
54+
parent.save_revision().publish()
55+
page_1 = GenericPageFactory(
56+
slug="bubble-tea",
57+
locale=locale("en"),
58+
parent=parent,
59+
body__0__text_section__title__value="I've Got a Lovely Bunch of Coconuts",
60+
)
61+
page_1.save_revision().publish()
62+
PageViewRestriction.objects.create(
63+
page=page_1, restriction_type="password", password="ticket"
64+
)
65+
66+
page_2 = GenericPageFactory(
67+
slug="chocolate",
68+
locale=locale("en"),
69+
parent=parent,
70+
body__0__text_section__title__value="There they are, all standing in a row",
71+
)
72+
page_2.save_revision().publish()
73+
SiteFactory(hostname="pycon", port=80, root_page=parent)
74+
75+
query = """
76+
query Page ($hostname: String!, $language: String!) {
77+
cmsPages(hostname: $hostname, language: $language){
78+
id
79+
}
80+
}
81+
"""
82+
83+
response = graphql_client.query(
84+
query, variables={"hostname": "pycon", "language": "en"}
85+
)
86+
87+
assert response["data"] == {
88+
"cmsPages": [
89+
{"id": str(parent.id)},
90+
{"id": str(page_2.id)},
91+
]
92+
}
93+
94+
5195
def test_pages_site_not_found(graphql_client):
5296
query = """
5397
query Page ($hostname: String!, $language: String!) {

0 commit comments

Comments
 (0)