Преглед изворни кода

restrict user for changing the option property except few fieldtype (#3666)

* restrict user for changing the option property

* test case modification
version-14
Manas Solanki пре 8 година
committed by Makarand Bauskar
родитељ
комит
96297e1ff4
2 измењених фајлова са 11 додато и 5 уклоњено
  1. +6
    -0
      frappe/custom/doctype/customize_form/customize_form.py
  2. +5
    -5
      frappe/custom/doctype/customize_form/test_customize_form.py

+ 6
- 0
frappe/custom/doctype/customize_form/customize_form.py Прегледај датотеку

@@ -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)




+ 5
- 5
frappe/custom/doctype/customize_form/test_customize_form.py Прегледај датотеку

@@ -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")



Loading…
Откажи
Сачувај