diff --git a/README.md b/README.md
index 454237812c71da953970f48393fc2142f6dee3e7..5599e94599e44eef72811f2b3fb1b341bb3f92f8 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,19 @@
-Dash-FastAPI-Admin v1.2.0
+Dash-FastAPI-Admin v1.2.1
基于Dash+FastAPI前后端分离的纯Python快速开发框架
-
+
+
## 平台简介
Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
diff --git a/dash-fastapi-backend/.env.dev b/dash-fastapi-backend/.env.dev
index 168937607546c174cc5ba9105fbfefb98dc89046..7dfa8170eae13eb9fd5337828b03595a4e7516b5 100644
--- a/dash-fastapi-backend/.env.dev
+++ b/dash-fastapi-backend/.env.dev
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
-APP_VERSION= '1.2.0'
+APP_VERSION= '1.2.1'
# 应用是否开启热重载
APP_RELOAD = true
diff --git a/dash-fastapi-backend/.env.prod b/dash-fastapi-backend/.env.prod
index bc743e925e08d3204581c2607ae33a8b0ad60212..b496d9ffc34333556e76f010e40108e7c5d5915f 100644
--- a/dash-fastapi-backend/.env.prod
+++ b/dash-fastapi-backend/.env.prod
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
-APP_VERSION= '1.2.0'
+APP_VERSION= '1.2.1'
# 应用是否开启热重载
APP_RELOAD = false
diff --git a/dash-fastapi-backend/module_admin/annotation/log_annotation.py b/dash-fastapi-backend/module_admin/annotation/log_annotation.py
index f1e0f706a1bd35d018988a44769c6c39a23d3492..46f80e610e59e304e94c77095019869e6fe1600e 100644
--- a/dash-fastapi-backend/module_admin/annotation/log_annotation.py
+++ b/dash-fastapi-backend/module_admin/annotation/log_annotation.py
@@ -49,7 +49,7 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
# 获取请求的url
oper_url = request.url.path
# 获取请求的ip及ip归属区域
- oper_ip = request.headers.get('X-Forwarded-For') if AppConfig.app_env == 'prod' else request.headers.get('remote_addr')
+ oper_ip = request.headers.get('remote_addr') if request.headers.get('is_browser') == 'no' else request.headers.get('X-Forwarded-For')
oper_location = '内网IP'
try:
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
diff --git a/dash-fastapi-backend/module_admin/aspect/interface_auth.py b/dash-fastapi-backend/module_admin/aspect/interface_auth.py
index a9d4f5eb1b8a368d191b0c1556ff331b0bec32e7..e17f324cd26c56ae006d8f785bc44285bfad04bb 100644
--- a/dash-fastapi-backend/module_admin/aspect/interface_auth.py
+++ b/dash-fastapi-backend/module_admin/aspect/interface_auth.py
@@ -1,4 +1,5 @@
from fastapi import Depends
+from typing import Union, List
from module_admin.entity.vo.user_vo import CurrentUserInfoServiceResponse
from module_admin.service.login_service import get_current_user
from utils.response_util import PermissionException
@@ -7,13 +8,50 @@ from utils.response_util import PermissionException
class CheckUserInterfaceAuth:
"""
校验当前用户是否具有相应的接口权限
+ :param perm: 权限标识
+ :param is_strict: 当传入的权限标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个权限标识,所有的校验结果都需要为True才会通过
"""
- def __init__(self, perm_str: str = 'common'):
- self.perm_str = perm_str
+ def __init__(self, perm: Union[str, List], is_strict: bool = False):
+ self.perm = perm
+ self.is_strict = is_strict
def __call__(self, current_user: CurrentUserInfoServiceResponse = Depends(get_current_user)):
user_auth_list = [item.perms for item in current_user.menu]
user_auth_list.append('common')
- if self.perm_str in user_auth_list:
- return True
+ if isinstance(self.perm, str):
+ if self.perm in user_auth_list:
+ return True
+ if isinstance(self.perm, list):
+ if self.is_strict:
+ if all([perm_str in user_auth_list for perm_str in self.perm]):
+ return True
+ else:
+ if any([perm_str in user_auth_list for perm_str in self.perm]):
+ return True
+ raise PermissionException(data="", message="该用户无此接口权限")
+
+
+class CheckRoleInterfaceAuth:
+ """
+ 根据角色校验当前用户是否具有相应的接口权限
+ :param role_key: 角色标识
+ :param is_strict: 当传入的角色标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个角色标识,所有的校验结果都需要为True才会通过
+ """
+ def __init__(self, role_key: Union[str, List], is_strict: bool = False):
+ self.role_key = role_key
+ self.is_strict = is_strict
+
+ def __call__(self, current_user: CurrentUserInfoServiceResponse = Depends(get_current_user)):
+ user_role_list = current_user.role
+ user_role_key_list = [role.role_key for role in user_role_list]
+ if isinstance(self.role_key, str):
+ if self.role_key in user_role_key_list:
+ return True
+ if isinstance(self.role_key, list):
+ if self.is_strict:
+ if all([role_key_str in user_role_key_list for role_key_str in self.role_key]):
+ return True
+ else:
+ if any([role_key_str in user_role_key_list for role_key_str in self.role_key]):
+ return True
raise PermissionException(data="", message="该用户无此接口权限")
diff --git a/dash-fastapi-frontend/utils/request.py b/dash-fastapi-frontend/utils/request.py
index a605dadbbc5691cd22f9d941d0dc4e26073a4fc0..51b4fc26827a40db165202bc61aa42465561e7fc 100644
--- a/dash-fastapi-frontend/utils/request.py
+++ b/dash-fastapi-frontend/utils/request.py
@@ -15,9 +15,9 @@ def api_request(method: str, url: str, is_headers: bool, params: Optional[dict]
remote_addr = request.headers.get("X-Forwarded-For") if AppConfig.app_env == 'prod' else request.remote_addr
if is_headers:
api_headers = {'Authorization': 'Bearer ' + authorization, 'remote_addr': remote_addr,
- 'User-Agent': user_agent}
+ 'User-Agent': user_agent, 'is_browser': 'no'}
else:
- api_headers = {'remote_addr': remote_addr, 'User-Agent': user_agent}
+ api_headers = {'remote_addr': remote_addr, 'User-Agent': user_agent, 'is_browser': 'no'}
try:
if method == 'get':
response = requests.get(url=api_url, params=params, data=data, json=json, headers=api_headers,
@@ -49,13 +49,13 @@ def api_request(method: str, url: str, is_headers: bool, params: Optional[dict]
if response_code == 200:
logger.info("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求参数:{}||请求结果:{}",
session.get('user_info').get('user_name') if session.get('user_info') else None,
- request.remote_addr, method, url,
+ remote_addr, method, url,
','.join([str(x) for x in data_list if x]),
response_message)
else:
logger.warning("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求参数:{}||请求结果:{}",
session.get('user_info').get('user_name') if session.get('user_info') else None,
- request.remote_addr, method, url,
+ remote_addr, method, url,
','.join([str(x) for x in data_list if x]),
response_message)
@@ -63,7 +63,7 @@ def api_request(method: str, url: str, is_headers: bool, params: Optional[dict]
except Exception as e:
logger.error("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求结果:{}",
session.get('user_info').get('user_name') if session.get('user_info') else None,
- request.remote_addr, method, url, str(e))
+ remote_addr, method, url, str(e))
session['code'] = 500
session['message'] = str(e)