* restrict user for changing the option property * test case modificationversion-14
@@ -68,6 +68,8 @@ allowed_fieldtype_change = (('Currency', 'Float', 'Percent'), ('Small Text', 'Da | |||||
('Text', 'Data'), ('Text', 'Text Editor', 'Code', 'Signature'), ('Data', 'Select'), | ('Text', 'Data'), ('Text', 'Text Editor', 'Code', 'Signature'), ('Data', 'Select'), | ||||
('Text', 'Small Text')) | ('Text', 'Small Text')) | ||||
allowed_fieldtype_for_options_change = ('Read Only', 'HTML', 'Select',) | |||||
class CustomizeForm(Document): | class CustomizeForm(Document): | ||||
def on_update(self): | def on_update(self): | ||||
frappe.db.sql("delete from tabSingles where doctype='Customize Form'") | frappe.db.sql("delete from tabSingles where doctype='Customize Form'") | ||||
@@ -197,6 +199,10 @@ class CustomizeForm(Document): | |||||
frappe.msgprint(_("You cannot unset 'Read Only' for field {0}").format(df.label)) | frappe.msgprint(_("You cannot unset 'Read Only' for field {0}").format(df.label)) | ||||
continue | continue | ||||
elif property == "options" and df.get("fieldtype") not in allowed_fieldtype_for_options_change: | |||||
frappe.msgprint(_("You can't set 'Options' for field {0}").format(df.label)) | |||||
continue | |||||
self.make_property_setter(property=property, value=df.get(property), | self.make_property_setter(property=property, value=df.get(property), | ||||
property_type=docfield_properties[property], fieldname=df.fieldname) | property_type=docfield_properties[property], fieldname=df.fieldname) | ||||
@@ -165,22 +165,22 @@ class TestCustomizeForm(unittest.TestCase): | |||||
df = d.get("fields", {"fieldname": "title"})[0] | df = d.get("fields", {"fieldname": "title"})[0] | ||||
# invalid fieldname | # invalid fieldname | ||||
df.options = """{doc_type} - {introduction_test}""" | |||||
df.default = """{doc_type} - {introduction_test}""" | |||||
self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization") | self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization") | ||||
# space in formatter | # space in formatter | ||||
df.options = """{doc_type} - {introduction text}""" | |||||
df.default = """{doc_type} - {introduction text}""" | |||||
self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization") | self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization") | ||||
# valid fieldname | # valid fieldname | ||||
df.options = """{doc_type} - {introduction_text}""" | |||||
df.default = """{doc_type} - {introduction_text}""" | |||||
d.run_method("save_customization") | d.run_method("save_customization") | ||||
# valid fieldname with escaped curlies | # valid fieldname with escaped curlies | ||||
df.options = """{{ {doc_type} }} - {introduction_text}""" | |||||
df.default = """{{ {doc_type} }} - {introduction_text}""" | |||||
d.run_method("save_customization") | d.run_method("save_customization") | ||||
# undo | # undo | ||||
df.options = None | |||||
df.default = None | |||||
d.run_method("save_customization") | d.run_method("save_customization") | ||||