1
+ from typing import List
1
2
import frappe
2
3
from frappe .model import default_fields , no_value_fields
3
4
from frappe .model .meta import Meta
@@ -8,6 +9,10 @@ def get_allowed_fieldnames_for_doctype(doctype: str, parent_doctype: str = None)
8
9
Gets a list of fieldnames that's allowed for the current User to
9
10
read on the specified doctype. This includes default_fields
10
11
"""
12
+ _from_locals = _get_allowed_fieldnames_from_locals (doctype , parent_doctype )
13
+ if _from_locals is not None :
14
+ return _from_locals
15
+
11
16
fieldnames = list (default_fields )
12
17
fieldnames .remove ("doctype" )
13
18
@@ -25,6 +30,12 @@ def get_allowed_fieldnames_for_doctype(doctype: str, parent_doctype: str = None)
25
30
26
31
fieldnames .append (df .fieldname )
27
32
33
+ _set_allowed_fieldnames_to_locals (
34
+ allowed_fields = fieldnames ,
35
+ doctype = doctype ,
36
+ parent_doctype = parent_doctype
37
+ )
38
+
28
39
return fieldnames
29
40
30
41
@@ -45,3 +56,30 @@ def _get_permlevel_read_access(meta: Meta):
45
56
_has_access_to .append (perm .get ("permlevel" ))
46
57
47
58
return _has_access_to
59
+
60
+
61
+ def _get_allowed_fieldnames_from_locals (doctype : str , parent_doctype : str = None ):
62
+
63
+ if not hasattr (frappe .local , "permlevel_fields" ):
64
+ frappe .local .permlevel_fields = dict ()
65
+
66
+ k = doctype
67
+ if parent_doctype :
68
+ k = (doctype , parent_doctype )
69
+
70
+ return frappe .local .permlevel_fields .get (k )
71
+
72
+
73
+ def _set_allowed_fieldnames_to_locals (
74
+ allowed_fields : List [str ],
75
+ doctype : str ,
76
+ parent_doctype : str = None ):
77
+
78
+ if not hasattr (frappe .local , "permlevel_fields" ):
79
+ frappe .local .permlevel_fields = dict ()
80
+
81
+ k = doctype
82
+ if parent_doctype :
83
+ k = (doctype , parent_doctype )
84
+
85
+ frappe .local .permlevel_fields [k ] = allowed_fields
0 commit comments