File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
dash-fastapi-backend/module_admin/aspect Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 11from fastapi import Depends
2+ from typing import Union , List
23from module_admin .entity .vo .user_vo import CurrentUserInfoServiceResponse
34from module_admin .service .login_service import get_current_user
45from utils .response_util import PermissionException
78class CheckUserInterfaceAuth :
89 """
910 校验当前用户是否具有相应的接口权限
11+ :param perm: 权限标识
12+ :param is_strict: 当传入的权限标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个权限标识,所有的校验结果都需要为True才会通过
1013 """
11- def __init__ (self , perm_str : str = 'common' ):
12- self .perm_str = perm_str
14+ def __init__ (self , perm : Union [str , List ], is_strict : bool = False ):
15+ self .perm = perm
16+ self .is_strict = is_strict
1317
1418 def __call__ (self , current_user : CurrentUserInfoServiceResponse = Depends (get_current_user )):
1519 user_auth_list = [item .perms for item in current_user .menu ]
1620 user_auth_list .append ('common' )
17- if self .perm_str in user_auth_list :
18- return True
21+ if isinstance (self .perm , str ):
22+ if self .perm in user_auth_list :
23+ return True
24+ if isinstance (self .perm , list ):
25+ if self .is_strict :
26+ if all ([perm_str in user_auth_list for perm_str in self .perm ]):
27+ return True
28+ else :
29+ if any ([perm_str in user_auth_list for perm_str in self .perm ]):
30+ return True
1931 raise PermissionException (data = "" , message = "该用户无此接口权限" )
You can’t perform that action at this time.
0 commit comments