fix(report_view): enforce print permission for reports

This commit is contained in:
AarDG10 2025-12-31 10:48:48 +05:30
parent e8a5529b98
commit 3a9d078dc3
3 changed files with 7 additions and 1 deletions

View file

@ -187,6 +187,9 @@ frappe.render_pdf = function (html, opts = {}) {
//Push the HTML content into an element
formData.append("html", html);
if (opts.doctype) {
formData.append("doctype", opts.doctype);
}
if (opts.orientation) {
formData.append("orientation", opts.orientation);
}

View file

@ -1531,6 +1531,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
},
{
label: __("Print"),
condition: () => frappe.model.can_print(this.doctype),
action: () => {
// prepare rows in their current state, sorted and filtered
const rows_in_order = this.datatable.datamanager.rowViewOrder

View file

@ -253,7 +253,9 @@ def download_pdf(
@frappe.whitelist()
def report_to_pdf(html, orientation="Landscape"):
def report_to_pdf(html, orientation="Landscape", doctype=None):
if doctype:
frappe.has_permission(doctype, "print", throw=True)
make_access_log(file_type="PDF", method="PDF", page=html)
frappe.local.response.filename = "report.pdf"
frappe.local.response.filecontent = get_pdf(html, {"orientation": orientation})