fix in permission engine: allow restrictions based on custom field
diff --git a/setup/doctype/permission_control/permission_control.py b/setup/doctype/permission_control/permission_control.py
index cb0575d..4fbd1dd 100644
--- a/setup/doctype/permission_control/permission_control.py
+++ b/setup/doctype/permission_control/permission_control.py
@@ -81,7 +81,12 @@
# get default values
# ------------------
def get_defaults(self, arg):
- match_key, with_profiles = arg.split('~~~')
+ if isinstance(arg, basestring):
+ import json
+ arg = json.loads(arg)
+
+ match_key = arg["match"]
+ with_profiles = arg["profiles"]
pl = ol = []
@@ -89,7 +94,9 @@
dl = [a for a in sql("select parent, ifnull(parenttype,'') as parenttype, ifnull(defvalue,'') as defvalue from tabDefaultValue where defkey=%s order by parenttype desc, parent asc", match_key, as_dict=1)]
# options
- tn = sql("select options from tabDocField where fieldname=%s and fieldtype='Link' and docstatus=0 limit 1", match_key)[0][0]
+ tn = webnotes.get_doctype(arg["doctype"]).get_options(match_key)
+
+ # tn = sql("select options from tabDocField where fieldname=%s and fieldtype='Link' and docstatus=0 limit 1", match_key)[0][0]
ol = [''] + [a[0] for a in sql("select name from `tab%s` where ifnull(docstatus,0)=0" % tn)]
# roles
diff --git a/setup/page/permission_engine/permission_engine.js b/setup/page/permission_engine/permission_engine.js
index 5f5630c..6edde4c 100644
--- a/setup/page/permission_engine/permission_engine.js
+++ b/setup/page/permission_engine/permission_engine.js
@@ -287,7 +287,11 @@
me.render_match_dialog(r, details);
}
// load the rules
- $c_obj('Permission Control','get_defaults', details.match + '~~~' + (this.profiles ? 'No' : 'Yes'), callback);
+ $c_obj('Permission Control','get_defaults', {
+ match: details.match,
+ profiles: this.profiles ? "No" : "Yes",
+ doctype: sel_val(me.type_select)
+ }, callback);
}
// --------------------------------------------