From 6231e1d96b18dc9fd5bf091e7a446e19297bd827 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:55:23 +0000 Subject: [PATCH] fix: avoid perm error on dashboard chart (#26150) (#26156) client side code is _never_ supposed to query doctype table. (cherry picked from commit c3fa4117f17464a6367e55e777ba6fdd1636c4ab) Co-authored-by: Ankush Menat --- .../dashboard_chart/dashboard_chart.js | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js index 3577e9c5ec0..31fb7e51675 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js @@ -529,29 +529,32 @@ frappe.ui.form.on("Dashboard Chart", { set_parent_document_type: async function (frm) { let document_type = frm.doc.document_type; - let doc_is_table = - document_type && - (await frappe.db.get_value("DocType", document_type, "istable")).message.istable; - - frm.set_df_property("parent_document_type", "hidden", !doc_is_table); - - if (document_type && doc_is_table) { - let parents = await frappe.xcall( - "frappe.desk.doctype.dashboard_chart.dashboard_chart.get_parent_doctypes", - { child_type: document_type } - ); + if (!document_type) { + frm.set_df_property("parent_document_type", "hidden", 1); + return; + } + frappe.model.with_doctype(document_type, async () => { + let doc_is_table = frappe.get_meta(document_type).istable; + frm.set_df_property("parent_document_type", "hidden", !doc_is_table); + + if (doc_is_table) { + let parents = await frappe.xcall( + "frappe.desk.doctype.dashboard_chart.dashboard_chart.get_parent_doctypes", + { child_type: document_type } + ); - frm.set_query("parent_document_type", function () { - return { - filters: { - name: ["in", parents], - }, - }; - }); + frm.set_query("parent_document_type", function () { + return { + filters: { + name: ["in", parents], + }, + }; + }); - if (parents.length === 1) { - frm.set_value("parent_document_type", parents[0]); + if (parents.length === 1) { + frm.set_value("parent_document_type", parents[0]); + } } - } + }); }, });