From 11801cfbd2a0e4806d417638465dcb7c9ccf4366 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 9 Sep 2014 15:24:13 +0530 Subject: [PATCH] Don't allow to set 'Allow on Submit' for standard fields. Fixes frappe/erpnext#956 --- .../core/doctype/customize_form/customize_form.py | 5 +++++ .../doctype/customize_form/test_customize_form.py | 14 ++++++++++++++ frappe/patches.txt | 1 + frappe/patches/v4_3/__init__.py | 0 .../v4_3/remove_allow_on_submit_customization.py | 11 +++++++++++ 5 files changed, 31 insertions(+) create mode 100644 frappe/patches/v4_3/__init__.py create mode 100644 frappe/patches/v4_3/remove_allow_on_submit_customization.py diff --git a/frappe/core/doctype/customize_form/customize_form.py b/frappe/core/doctype/customize_form/customize_form.py index 8f9f7f8a9d..04d74eb287 100644 --- a/frappe/core/doctype/customize_form/customize_form.py +++ b/frappe/core/doctype/customize_form/customize_form.py @@ -117,6 +117,11 @@ class CustomizeForm(Document): if property == "fieldtype": self.validate_fieldtype_change(df, meta_df[0].get(property), df.get(property)) + elif property == "allow_on_submit" and df.get(property): + frappe.msgprint(_("Row {0}: Not allowed to enable Allow on Submit for standard fields")\ + .format(df.idx)) + continue + self.make_property_setter(property=property, value=df.get(property), property_type=self.docfield_properties[property], fieldname=df.fieldname) diff --git a/frappe/core/doctype/customize_form/test_customize_form.py b/frappe/core/doctype/customize_form/test_customize_form.py index 7a1e4e6b4d..db4115fb8b 100644 --- a/frappe/core/doctype/customize_form/test_customize_form.py +++ b/frappe/core/doctype/customize_form/test_customize_form.py @@ -159,3 +159,17 @@ class TestCustomizeForm(unittest.TestCase): frappe.local.test_objects["Property Setter"] = [] make_test_records_for_doctype("Property Setter") + + def test_set_allow_on_submit(self): + d = self.get_customize_form("User") + d.get("customize_form_fields", {"fieldname": "first_name"})[0].allow_on_submit = 1 + d.get("customize_form_fields", {"fieldname": "test_custom_field"})[0].allow_on_submit = 1 + d.run_method("save_customization") + + d = self.get_customize_form("User") + + # don't allow for standard fields + self.assertEquals(d.get("customize_form_fields", {"fieldname": "first_name"})[0].allow_on_submit or 0, 0) + + # allow for custom field + self.assertEquals(d.get("customize_form_fields", {"fieldname": "test_custom_field"})[0].allow_on_submit, 1) diff --git a/frappe/patches.txt b/frappe/patches.txt index 6e8c2fa47e..1b9d2f143c 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -54,3 +54,4 @@ execute:frappe.reload_doc('website', 'doctype', 'web_form') #2014-09-04 execute:frappe.reload_doc('website', 'doctype', 'web_form_field') #2014-09-04 frappe.patches.v4_2.refactor_website_routing frappe.patches.v4_2.set_assign_in_doc +frappe.patches.v4_3.remove_allow_on_submit_customization diff --git a/frappe/patches/v4_3/__init__.py b/frappe/patches/v4_3/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/patches/v4_3/remove_allow_on_submit_customization.py b/frappe/patches/v4_3/remove_allow_on_submit_customization.py new file mode 100644 index 0000000000..0e6cd3a11e --- /dev/null +++ b/frappe/patches/v4_3/remove_allow_on_submit_customization.py @@ -0,0 +1,11 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for d in frappe.get_list("Property Setter", fields=["name", "doc_type"], + filters={"doctype_or_field": "DocField", "property": "allow_on_submit", "value": "1"}, ignore_permissions=True): + frappe.delete_doc("Property Setter", d.name) + frappe.clear_cache(doctype=d.doc_type)