Merge pull request #37013 from stravo1/fix-cached-404-website-permission

This commit is contained in:
Suraj Shetty 2026-02-25 11:38:41 +05:30 committed by GitHub
commit e1e65238f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ import os
from urllib.parse import urlparse
import frappe
from frappe.website.page_renderers.document_page import _find_matching_document_webview
from frappe.website.page_renderers.template_page import TemplatePage
from frappe.website.utils import can_cache
@ -26,10 +27,26 @@ class NotFoundPage(TemplatePage):
def can_cache_404(self):
# do not cache 404 for custom homepages
return can_cache() and self.request_url and not self.is_custom_home_page()
# also skip caching docs with website permission checks (access is dynamic)
return (
can_cache()
and self.request_url
and not self.is_custom_home_page()
and not self.has_website_permission_check()
)
def is_custom_home_page(self):
url_parts = urlparse(self.request_url)
request_url = os.path.splitext(url_parts.path)[0]
request_path = os.path.splitext(self.request_path)[0]
return request_url in HOMEPAGE_PATHS and request_path not in HOMEPAGE_PATHS
def has_website_permission_check(self):
request_path = os.path.splitext(self.request_path)[0]
if not (document := _find_matching_document_webview(request_path)):
return False
doctype, docname = document
doc = frappe.get_cached_doc(doctype, docname)
return hasattr(doc, "has_website_permission") or bool(
frappe.get_hooks("has_website_permission", {}).get(doctype)
)