style: 使用ruff格式化aspect模块,优化导入
This commit is contained in:
@@ -1,14 +1,21 @@
|
|||||||
from fastapi import Depends
|
from fastapi import Depends
|
||||||
|
from typing import Optional
|
||||||
from module_admin.entity.vo.user_vo import CurrentUserModel
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||||
from module_admin.service.login_service import LoginService
|
from module_admin.service.login_service import LoginService
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
|
|
||||||
class GetDataScope:
|
class GetDataScope:
|
||||||
"""
|
"""
|
||||||
获取当前用户数据权限对应的查询sql语句
|
获取当前用户数据权限对应的查询sql语句
|
||||||
"""
|
"""
|
||||||
def __init__(self, query_alias: Optional[str] = '', db_alias: Optional[str] = 'db', user_alias: Optional[str] = 'user_id', dept_alias: Optional[str] = 'dept_id'):
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
query_alias: Optional[str] = '',
|
||||||
|
db_alias: Optional[str] = 'db',
|
||||||
|
user_alias: Optional[str] = 'user_id',
|
||||||
|
dept_alias: Optional[str] = 'dept_id',
|
||||||
|
):
|
||||||
self.query_alias = query_alias
|
self.query_alias = query_alias
|
||||||
self.db_alias = db_alias
|
self.db_alias = db_alias
|
||||||
self.user_alias = user_alias
|
self.user_alias = user_alias
|
||||||
@@ -17,7 +24,9 @@ class GetDataScope:
|
|||||||
def __call__(self, current_user: CurrentUserModel = Depends(LoginService.get_current_user)):
|
def __call__(self, current_user: CurrentUserModel = Depends(LoginService.get_current_user)):
|
||||||
user_id = current_user.user.user_id
|
user_id = current_user.user.user_id
|
||||||
dept_id = current_user.user.dept_id
|
dept_id = current_user.user.dept_id
|
||||||
role_datascope_list = [dict(role_id=item.role_id, data_scope=int(item.data_scope)) for item in current_user.user.role]
|
role_datascope_list = [
|
||||||
|
dict(role_id=item.role_id, data_scope=int(item.data_scope)) for item in current_user.user.role
|
||||||
|
]
|
||||||
max_data_scope_dict = min(role_datascope_list, key=lambda x: x['data_scope'])
|
max_data_scope_dict = min(role_datascope_list, key=lambda x: x['data_scope'])
|
||||||
max_role_id = max_data_scope_dict['role_id']
|
max_role_id = max_data_scope_dict['role_id']
|
||||||
max_data_scope = max_data_scope_dict['data_scope']
|
max_data_scope = max_data_scope_dict['data_scope']
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
from fastapi import Depends
|
from fastapi import Depends
|
||||||
from typing import Union, List
|
from typing import List, Union
|
||||||
|
from exceptions.exception import PermissionException
|
||||||
from module_admin.entity.vo.user_vo import CurrentUserModel
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||||
from module_admin.service.login_service import LoginService
|
from module_admin.service.login_service import LoginService
|
||||||
from exceptions.exception import PermissionException
|
|
||||||
|
|
||||||
|
|
||||||
class CheckUserInterfaceAuth:
|
class CheckUserInterfaceAuth:
|
||||||
@@ -11,6 +11,7 @@ class CheckUserInterfaceAuth:
|
|||||||
:param perm: 权限标识
|
:param perm: 权限标识
|
||||||
:param is_strict: 当传入的权限标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个权限标识,所有的校验结果都需要为True才会通过
|
:param is_strict: 当传入的权限标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个权限标识,所有的校验结果都需要为True才会通过
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, perm: Union[str, List], is_strict: bool = False):
|
def __init__(self, perm: Union[str, List], is_strict: bool = False):
|
||||||
self.perm = perm
|
self.perm = perm
|
||||||
self.is_strict = is_strict
|
self.is_strict = is_strict
|
||||||
@@ -29,7 +30,7 @@ class CheckUserInterfaceAuth:
|
|||||||
else:
|
else:
|
||||||
if any([perm_str in user_auth_list for perm_str in self.perm]):
|
if any([perm_str in user_auth_list for perm_str in self.perm]):
|
||||||
return True
|
return True
|
||||||
raise PermissionException(data="", message="该用户无此接口权限")
|
raise PermissionException(data='', message='该用户无此接口权限')
|
||||||
|
|
||||||
|
|
||||||
class CheckRoleInterfaceAuth:
|
class CheckRoleInterfaceAuth:
|
||||||
@@ -38,6 +39,7 @@ class CheckRoleInterfaceAuth:
|
|||||||
:param role_key: 角色标识
|
:param role_key: 角色标识
|
||||||
:param is_strict: 当传入的角色标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个角色标识,所有的校验结果都需要为True才会通过
|
:param is_strict: 当传入的角色标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个角色标识,所有的校验结果都需要为True才会通过
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, role_key: Union[str, List], is_strict: bool = False):
|
def __init__(self, role_key: Union[str, List], is_strict: bool = False):
|
||||||
self.role_key = role_key
|
self.role_key = role_key
|
||||||
self.is_strict = is_strict
|
self.is_strict = is_strict
|
||||||
@@ -55,5 +57,4 @@ class CheckRoleInterfaceAuth:
|
|||||||
else:
|
else:
|
||||||
if any([role_key_str in user_role_key_list for role_key_str in self.role_key]):
|
if any([role_key_str in user_role_key_list for role_key_str in self.role_key]):
|
||||||
return True
|
return True
|
||||||
raise PermissionException(data="", message="该用户无此接口权限")
|
raise PermissionException(data='', message='该用户无此接口权限')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user