refactor: Check parent validity using parent meta
This commit is contained in:
parent
95258bf9f2
commit
cb76118268
1 changed files with 5 additions and 8 deletions
|
|
@ -97,7 +97,7 @@ def has_permission(doctype, ptype="read", doc=None, verbose=False, user=None, ra
|
|||
if not perm:
|
||||
perm = false_if_not_shared()
|
||||
|
||||
return perm
|
||||
return bool(perm)
|
||||
|
||||
def get_doc_permissions(doc, user=None, ptype=None):
|
||||
"""Returns a dict of evaluated permissions for given `doc` like `{"read":1, "write":1}`"""
|
||||
|
|
@ -592,10 +592,7 @@ def has_child_table_permission(child_doctype, ptype="read", child_doc=None,
|
|||
|
||||
|
||||
def is_parent_valid(child_doctype, parent_doctype):
|
||||
filters = {
|
||||
"options": child_doctype,
|
||||
"fieldtype": "Table",
|
||||
"parent": parent_doctype
|
||||
}
|
||||
return not frappe.is_table(parent_doctype) and (frappe.db.exists("DocField", filters, cache=True)
|
||||
or frappe.db.exists("Custom Field", filters, cache=True))
|
||||
from frappe.core.utils import find
|
||||
parent_meta = frappe.get_meta(parent_doctype)
|
||||
child_table_field_exist = find(parent_meta.get_table_fields(), lambda d: d.options == child_doctype)
|
||||
return not frappe.is_table(parent_doctype) and child_table_field_exist
|
||||
Loading…
Add table
Reference in a new issue