[report] Don't run disabled script/query report

This commit is contained in:
Anand Doshi 2014-08-06 16:40:15 +05:30
parent 1674a2d6f1
commit c240eaaf84
3 changed files with 30 additions and 7 deletions

View file

@ -11,7 +11,22 @@ cur_frm.cscript.refresh = function(doc) {
frappe.set_route("query-report", doc.name);
break;
}
}, "icon-table")
}, "icon-table");
if (doc.is_standard === "Yes") {
cur_frm.add_custom_button(doc.disabled ? __("Enable Report") : __("Disable Report"), function() {
$.ajax({
url: "/api/resource/Report/" + encodeURIComponent(doc.name),
type: "POST",
data: {
run_method: "toggle_disable",
disable: doc.disabled ? 0 : 1
}
}).always(function() {
cur_frm.reload_doc();
});
}, doc.disabled ? "icon-ok" : "icon-off");
}
cur_frm.set_intro("");
switch(doc.report_type) {

View file

@ -3,7 +3,8 @@
from __future__ import unicode_literals
import frappe
from frappe import conf, _
from frappe import _
from frappe.utils import cint
from frappe.model.document import Document
@ -15,7 +16,7 @@ class Report(Document):
if not self.is_standard:
self.is_standard = "No"
if frappe.session.user=="Administrator" and getattr(conf, 'developer_mode',0)==1:
if frappe.session.user=="Administrator" and getattr(frappe.local.conf, 'developer_mode',0)==1:
self.is_standard = "Yes"
if self.is_standard == "Yes" and frappe.session.user!="Administrator":
@ -32,6 +33,10 @@ class Report(Document):
def export_doc(self):
from frappe.modules.export_file import export_to_files
if self.is_standard == 'Yes' and (conf.get('developer_mode') or 0) == 1:
if self.is_standard == 'Yes' and (frappe.local.conf.get('developer_mode') or 0) == 1:
export_to_files(record_list=[['Report', self.name]],
record_module=self.module)
@Document.whitelist
def toggle_disable(self, disable):
self.db_set("disabled", cint(disable))

View file

@ -14,11 +14,14 @@ import frappe.widgets.reportview
def get_report_doc(report_name):
doc = frappe.get_doc("Report", report_name)
if not doc.has_permission("read"):
raise frappe.PermissionError("You don't have access to: {report}".format(report=report_name))
frappe.throw(_("You don't have access to Report: {0}").format(report_name), frappe.PermissionError)
if not frappe.has_permission(doc.ref_doctype, "report"):
raise frappe.PermissionError("You don't have access to get a report on: {doctype}".format(
doctype=doc.ref_doctype))
frappe.throw(_("You don't have permission to get a report on: {0}").format(doc.ref_doctype),
frappe.PermissionError)
if doc.disabled:
frappe.throw(_("Report {0} is disabled").format(report_name))
return doc