MCPcopy Create free account
hub / github.com/dataease/SQLBot / transTreeItem

Function transTreeItem

backend/apps/datasource/crud/row_permission.py:47–175  ·  view source on GitHub ↗
(session: SessionDep, current_user: CurrentUser, item: Dict, ds: CoreDatasource)

Source from the content-addressed store, hash-verified

45
46
47def transTreeItem(session: SessionDep, current_user: CurrentUser, item: Dict, ds: CoreDatasource) -> str | None:
48 res: str = None
49 field = session.query(CoreField).filter(CoreField.id == int(item['field_id'])).first()
50 if field is None:
51 return None
52
53 db = DB.get_db(ds.type)
54 whereName = db.prefix + field.field_name + db.suffix
55 whereTerm = transFilterTerm(item['term'])
56
57 if item['filter_type'] == 'enum':
58 if len(item['enum_value']) > 0:
59 if ds['type'] == 'sqlServer' and (
60 field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'):
61 res = "(" + whereName + " IN (N'" + "',N'".join(item['enum_value']) + "'))"
62 else:
63 res = "(" + whereName + " IN ('" + "','".join(item['enum_value']) + "'))"
64 else:
65 # if system variable, do check and get value
66 # new field: value_type(variable or normal), variable_id
67 value_type = item.get('value_type')
68 if value_type and value_type == 'variable':
69 # get system variable
70 variable_id = item.get('variable_id')
71 if variable_id is not None:
72 sys_variable = session.query(SystemVariable).filter(SystemVariable.id == variable_id).first()
73 if sys_variable is None:
74 return None
75
76 # do inner system variable
77 if sys_variable.type == 'system':
78 res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user, ds, field, item)
79 else:
80 # check user variable
81 user_variables = current_user.system_variables
82 if user_variables is None or len(user_variables) == 0 or not userHaveVariable(user_variables,
83 sys_variable):
84 return None
85 else:
86 # get user variable
87 u_variable = None
88 for u in user_variables:
89 if u.get('variableId') == sys_variable.id:
90 u_variable = u
91 break
92 if u_variable is None:
93 return None
94
95 # check value
96 values = u_variable.get('variableValues')
97 if sys_variable.var_type == 'text':
98 set_sys = set(sys_variable.value)
99 values = [x for x in values if x in set_sys]
100 if values is None or len(values) == 0:
101 return None
102 elif sys_variable.var_type == 'number':
103 if (sys_variable.value[0] is not None and values[0] < sys_variable.value[0]) or (
104 sys_variable.value[1] is not None and values[0] > sys_variable.value[1]):

Callers 1

transTreeToWhereFunction · 0.85

Calls 8

transFilterTermFunction · 0.85
getSysVariableValueFunction · 0.85
userHaveVariableFunction · 0.85
setFunction · 0.85
get_dbMethod · 0.80
getMethod · 0.65
firstMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected