瀏覽代碼

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', 'Small Text'))

allowed_fieldtype_for_options_change = ('Read Only', 'HTML', 'Select',)

class CustomizeForm(Document):
def on_update(self):
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))
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),
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]

# invalid fieldname
df.options = """{doc_type} - {introduction_test}"""
df.default = """{doc_type} - {introduction_test}"""
self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")

# space in formatter
df.options = """{doc_type} - {introduction text}"""
df.default = """{doc_type} - {introduction text}"""
self.assertRaises(InvalidFieldNameError, d.run_method, "save_customization")

# valid fieldname
df.options = """{doc_type} - {introduction_text}"""
df.default = """{doc_type} - {introduction_text}"""
d.run_method("save_customization")

# valid fieldname with escaped curlies
df.options = """{{ {doc_type} }} - {introduction_text}"""
df.default = """{{ {doc_type} }} - {introduction_text}"""
d.run_method("save_customization")

# undo
df.options = None
df.default = None
d.run_method("save_customization")


Loading…
取消
儲存