From 2372fd8c0208580e1f1908fc0c08ba3dd0c5f4c7 Mon Sep 17 00:00:00 2001 From: Soham Kulkarni <77533095+sokumon@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:43:05 +0530 Subject: [PATCH] fix: check if attached doctype exists (#30911) * fix: return False if attached doctype is not found * fix(UX): add a open url button in file form * fix(typo): add translate to string * fix: check if it is absolute url * fix: return false via module not found error --- frappe/core/doctype/file/file.js | 5 +++++ frappe/core/doctype/file/file.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/frappe/core/doctype/file/file.js b/frappe/core/doctype/file/file.js index 94432a51c7..b6385d68ff 100644 --- a/frappe/core/doctype/file/file.js +++ b/frappe/core/doctype/file/file.js @@ -1,5 +1,10 @@ frappe.ui.form.on("File", { refresh: function (frm) { + frm.add_custom_button(__("View File"), () => { + if (!frappe.utils.is_url(frm.doc.file_url)) { + window.open(window.location.origin + frm.doc.file_url); + } + }); if (!frm.doc.is_folder) { // add download button frm.add_custom_button(__("Download"), () => frm.trigger("download"), "fa fa-download"); diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 306bee91d1..ab560deefe 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -818,6 +818,8 @@ def has_permission(doc, ptype=None, user=None, debug=False): try: ref_doc = frappe.get_doc(attached_to_doctype, attached_to_name) + except ModuleNotFoundError: + return False except frappe.DoesNotExistError: frappe.clear_last_message() return False