Skip to content

Commit a6eabb1

Browse files
committed
feat: support system variable
1 parent 412660b commit a6eabb1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

backend/apps/datasource/crud/row_permission.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Date: 2025/6/25
33

44
from typing import List, Dict
5+
56
from apps.datasource.models.datasource import CoreField, CoreDatasource
67
from apps.db.constant import DB
78
from apps.system.models.system_variable_model import SystemVariable
@@ -74,7 +75,7 @@ def transTreeItem(session: SessionDep, current_user: CurrentUser, item: Dict, ds
7475

7576
# do inner system variable
7677
if sys_variable.type == 'system':
77-
res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user)
78+
res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user, ds, field)
7879
else:
7980
# check user variable
8081
user_variables = current_user.system_variables
@@ -215,10 +216,17 @@ def userHaveVariable(user_variables: List, sys_variable: SystemVariable):
215216
return False
216217

217218

218-
def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser):
219+
def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, ds: CoreDatasource, field: CoreField):
220+
v = None
219221
if sys_variable.value[0] == 'name':
220-
return current_user.name
222+
v = current_user.name
221223
if sys_variable.value[0] == 'account':
222-
return current_user.account
224+
v = current_user.account
223225
if sys_variable.value[0] == 'email':
224-
return current_user.email
226+
v = current_user.email
227+
228+
if ds.type == 'sqlServer' and (
229+
field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'):
230+
return f"N'{v}'"
231+
else:
232+
return f"'{v}'"

0 commit comments

Comments
 (0)