1313from common .core .db import engine
1414from apps .system .schemas .system_schema import UserInfoDTO
1515
16+ from common .utils .locale import I18n
17+ i18n = I18n ()
1618
1719class SqlbotPermission (BaseModel ):
1820 role : Optional [list [str ]] = None
@@ -49,6 +51,7 @@ def decorator(func):
4951 @wraps (func )
5052 async def wrapper (* args , ** kwargs ):
5153 request = RequestContext .get_request ()
54+
5255 current_user : UserInfoDTO = getattr (request .state , 'current_user' , None )
5356 if not current_user :
5457 raise HTTPException (
@@ -57,6 +60,8 @@ async def wrapper(*args, **kwargs):
5760 )
5861 current_oid = current_user .oid
5962
63+ trans = i18n (request )
64+
6065 if current_user .isAdmin and not permission .type :
6166 return await func (* args , ** kwargs )
6267 role_list = permission .role
@@ -65,9 +70,11 @@ async def wrapper(*args, **kwargs):
6570
6671 if role_list :
6772 if 'admin' in role_list and not current_user .isAdmin :
68- raise Exception ('no permission to execute, only for admin' )
73+ #raise Exception('no permission to execute, only for admin')
74+ raise Exception (trans ('i18n_permission.only_admin' ))
6975 if 'ws_admin' in role_list and current_user .weight == 0 and not current_user .isAdmin :
70- raise Exception ('no permission to execute, only for workspace admin' )
76+ #raise Exception('no permission to execute, only for workspace admin')
77+ raise Exception (trans ('i18n_permission.only_ws_admin' ))
7178 if not resource_type :
7279 return await func (* args , ** kwargs )
7380 if keyExpression :
@@ -81,7 +88,8 @@ async def wrapper(*args, **kwargs):
8188 value = bound_args .args [index ]
8289 if await check_ws_permission (current_oid , resource_type , value ):
8390 return await func (* args , ** kwargs )
84- raise Exception ('no permission to execute or resource do not exist!' )
91+ #raise Exception('no permission to execute or resource do not exist!')
92+ raise Exception (trans ('i18n_permission.permission_resource_limit' ))
8593
8694 parts = keyExpression .split ('.' )
8795 if not bound_args .arguments .get (parts [0 ]):
@@ -91,7 +99,7 @@ async def wrapper(*args, **kwargs):
9199 value = getattr (value , part )
92100 if await check_ws_permission (current_oid , resource_type , value ):
93101 return await func (* args , ** kwargs )
94- raise Exception ('no permission to execute or resource do not exist!' )
102+ raise Exception (trans ( 'i18n_permission.permission_resource_limit' ) )
95103
96104 return await func (* args , ** kwargs )
97105
0 commit comments