Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions backend/apps/datasource/crud/row_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Date: 2025/6/25

from typing import List, Dict

from apps.datasource.models.datasource import CoreField, CoreDatasource
from apps.db.constant import DB
from apps.system.models.system_variable_model import SystemVariable
Expand Down Expand Up @@ -74,7 +75,7 @@ def transTreeItem(session: SessionDep, current_user: CurrentUser, item: Dict, ds

# do inner system variable
if sys_variable.type == 'system':
res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user)
res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user, ds, field, item)
else:
# check user variable
user_variables = current_user.system_variables
Expand Down Expand Up @@ -215,10 +216,42 @@ def userHaveVariable(user_variables: List, sys_variable: SystemVariable):
return False


def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser):
def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, ds: CoreDatasource, field: CoreField,
item: Dict, ):
v = None
if sys_variable.value[0] == 'name':
return current_user.name
v = current_user.name
if sys_variable.value[0] == 'account':
return current_user.account
v = current_user.account
if sys_variable.value[0] == 'email':
return current_user.email
v = current_user.email

whereValue = ''
if item['term'] == 'null':
whereValue = ''
elif item['term'] == 'not_null':
whereValue = ''
elif item['term'] == 'empty':
whereValue = "''"
elif item['term'] == 'not_empty':
whereValue = "''"
elif item['term'] == 'in' or item['term'] == 'not in':
if ds.type == 'sqlServer' and (
field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'):
whereValue = f"(N'{v}')"
else:
whereValue = f"('{v}')"
elif item['term'] == 'like' or item['term'] == 'not like':
if ds.type == 'sqlServer' and (
field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'):
whereValue = f"N'%{v}%'"
else:
whereValue = f"'%{v}%'"
else:
if ds.type == 'sqlServer' and (
field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'):
whereValue = f"N'{v}'"
else:
whereValue = f"'{v}'"

return whereValue
Loading