Skip to content

Commit

Permalink
Prevent viewing pages outside their published dates range
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Aug 26, 2022
1 parent 5174cda commit 04dcef5
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cms/utils/page.py
Expand Up @@ -138,7 +138,7 @@ def get_page_from_request(request, use_path=None, clean_path=None):
The page slug can then be resolved to a Page model object
"""
from cms.utils.page_permissions import user_can_view_page_draft
from cms.utils.page_permissions import user_can_view_page_draft, user_can_publish_page

if not bool(use_path) and hasattr(request, '_current_page_cache'):
# The following is set by CurrentPageMiddleware
Expand Down Expand Up @@ -171,14 +171,13 @@ def get_page_from_request(request, use_path=None, clean_path=None):
# In this case the selected page is not reachable
if page and not draft:
now = timezone.now()
unpublished_ancestors = (
page
.get_ancestor_pages()
.filter(
Q(publication_date__gt=now) | Q(publication_end_date__lt=now),
)
)
if unpublished_ancestors.exists():
if not user_can_publish_page(request.user, page) and (
page.publication_date and page.publication_date > now
or page.publication_end_date and page.publication_end_date < now
or page.get_ancestor_pages().filter(
Q(publication_date__gt=now) | Q(publication_end_date__lt=now)
).exists()
):
page = None
return page

Expand Down

0 comments on commit 04dcef5

Please sign in to comment.