Merge pull request #28868 from akhilnarang/printview-cleanup-checks

chore(printview): change error message
This commit is contained in:
Akhil Narang 2024-12-23 15:27:54 +05:30 committed by GitHub
commit 21a6d2a717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 7 deletions

View file

@ -562,7 +562,7 @@ class TestDocumentWebView(IntegrationTestCase):
# without key
url_without_key = f"/ToDo/{todo.name}"
self.assertEqual(self.get(url_without_key).status, "403 FORBIDDEN")
self.assertEqual(self.get(url_without_key).status, "404 NOT FOUND")
# Logged-in user can access the page without key
self.assertEqual(self.get(url_without_key, "Administrator").status, "200 OK")

View file

@ -217,7 +217,9 @@ from frappe.deprecation_dumpster import read_multi_pdf
@frappe.whitelist(allow_guest=True)
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0, language=None, letterhead=None):
def download_pdf(
doctype: str, name: str, format=None, doc=None, no_letterhead=0, language=None, letterhead=None
):
doc = doc or frappe.get_doc(doctype, name)
validate_print_permission(doc)

View file

@ -375,15 +375,18 @@ def get_rendered_raw_commands(doc: str, name: str | None = None, print_format: s
def validate_print_permission(doc: "Document") -> None:
if frappe.has_website_permission(doc):
return
for ptype in ("read", "print"):
if frappe.has_permission(doc.doctype, ptype, doc) or frappe.has_website_permission(doc):
if frappe.has_permission(doc.doctype, ptype, doc):
return
key = frappe.form_dict.key
if key and isinstance(key, str):
if (key := frappe.form_dict.key) and isinstance(key, str):
validate_key(key, doc)
else:
raise frappe.PermissionError(_("You do not have permission to view this document"))
return
frappe.throw(_("{0} {1} not found").format(_(doc.doctype), doc.name), frappe.DoesNotExistError)
def validate_key(key: str, doc: "Document") -> None: