From a6eabb1a64bbd84575bf4c7f9d252d99cb661330 Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 17 Mar 2026 10:34:52 +0800 Subject: [PATCH 1/2] feat: support system variable --- backend/apps/datasource/crud/row_permission.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/apps/datasource/crud/row_permission.py b/backend/apps/datasource/crud/row_permission.py index 21b6f26bf..584624f1f 100644 --- a/backend/apps/datasource/crud/row_permission.py +++ b/backend/apps/datasource/crud/row_permission.py @@ -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 @@ -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) else: # check user variable user_variables = current_user.system_variables @@ -215,10 +216,17 @@ 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): + 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 + + if ds.type == 'sqlServer' and ( + field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'): + return f"N'{v}'" + else: + return f"'{v}'" From b079bdbeda0dc3256e59c148dc0a40bfe0397db9 Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 17 Mar 2026 10:51:20 +0800 Subject: [PATCH 2/2] feat: support system variable --- .../apps/datasource/crud/row_permission.py | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/backend/apps/datasource/crud/row_permission.py b/backend/apps/datasource/crud/row_permission.py index 584624f1f..86fbc9b76 100644 --- a/backend/apps/datasource/crud/row_permission.py +++ b/backend/apps/datasource/crud/row_permission.py @@ -75,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, ds, field) + res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user, ds, field, item) else: # check user variable user_variables = current_user.system_variables @@ -216,7 +216,8 @@ def userHaveVariable(user_variables: List, sys_variable: SystemVariable): return False -def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, ds: CoreDatasource, field: CoreField): +def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, ds: CoreDatasource, field: CoreField, + item: Dict, ): v = None if sys_variable.value[0] == 'name': v = current_user.name @@ -225,8 +226,32 @@ def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, if sys_variable.value[0] == 'email': v = current_user.email - if ds.type == 'sqlServer' and ( - field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'): - return f"N'{v}'" + 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: - return f"'{v}'" + 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