Skip to content

Commit e0c7f0b

Browse files
insistencegitee-org
authored andcommitted
!19 Dash-FastAPI-Admin v1.2.1
Merge pull request !19 from insistence/develop
2 parents 30dd792 + 4bcd489 commit e0c7f0b

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.2.0</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.2.1</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.2.0-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.2.1-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
1111
<img src="https://img.shields.io/badge/python-3.8 | 3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
1313
</p>
1414

1515

16+
1617
## 平台简介
1718

1819
Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。

dash-fastapi-backend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.2.0'
13+
APP_VERSION= '1.2.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616

dash-fastapi-backend/.env.prod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.2.0'
13+
APP_VERSION= '1.2.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616

dash-fastapi-backend/module_admin/annotation/log_annotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def wrapper(*args, **kwargs):
4949
# 获取请求的url
5050
oper_url = request.url.path
5151
# 获取请求的ip及ip归属区域
52-
oper_ip = request.headers.get('X-Forwarded-For') if AppConfig.app_env == 'prod' else request.headers.get('remote_addr')
52+
oper_ip = request.headers.get('remote_addr') if request.headers.get('is_browser') == 'no' else request.headers.get('X-Forwarded-For')
5353
oper_location = '内网IP'
5454
try:
5555
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fastapi import Depends
2+
from typing import Union, List
23
from module_admin.entity.vo.user_vo import CurrentUserInfoServiceResponse
34
from module_admin.service.login_service import get_current_user
45
from utils.response_util import PermissionException
@@ -7,13 +8,50 @@
78
class 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
31+
raise PermissionException(data="", message="该用户无此接口权限")
32+
33+
34+
class CheckRoleInterfaceAuth:
35+
"""
36+
根据角色校验当前用户是否具有相应的接口权限
37+
:param role_key: 角色标识
38+
:param is_strict: 当传入的角色标识是list类型时,是否开启严格模式,开启表示会校验列表中的每一个角色标识,所有的校验结果都需要为True才会通过
39+
"""
40+
def __init__(self, role_key: Union[str, List], is_strict: bool = False):
41+
self.role_key = role_key
42+
self.is_strict = is_strict
43+
44+
def __call__(self, current_user: CurrentUserInfoServiceResponse = Depends(get_current_user)):
45+
user_role_list = current_user.role
46+
user_role_key_list = [role.role_key for role in user_role_list]
47+
if isinstance(self.role_key, str):
48+
if self.role_key in user_role_key_list:
49+
return True
50+
if isinstance(self.role_key, list):
51+
if self.is_strict:
52+
if all([role_key_str in user_role_key_list for role_key_str in self.role_key]):
53+
return True
54+
else:
55+
if any([role_key_str in user_role_key_list for role_key_str in self.role_key]):
56+
return True
1957
raise PermissionException(data="", message="该用户无此接口权限")

dash-fastapi-frontend/utils/request.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def api_request(method: str, url: str, is_headers: bool, params: Optional[dict]
1515
remote_addr = request.headers.get("X-Forwarded-For") if AppConfig.app_env == 'prod' else request.remote_addr
1616
if is_headers:
1717
api_headers = {'Authorization': 'Bearer ' + authorization, 'remote_addr': remote_addr,
18-
'User-Agent': user_agent}
18+
'User-Agent': user_agent, 'is_browser': 'no'}
1919
else:
20-
api_headers = {'remote_addr': remote_addr, 'User-Agent': user_agent}
20+
api_headers = {'remote_addr': remote_addr, 'User-Agent': user_agent, 'is_browser': 'no'}
2121
try:
2222
if method == 'get':
2323
response = requests.get(url=api_url, params=params, data=data, json=json, headers=api_headers,
@@ -49,21 +49,21 @@ def api_request(method: str, url: str, is_headers: bool, params: Optional[dict]
4949
if response_code == 200:
5050
logger.info("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求参数:{}||请求结果:{}",
5151
session.get('user_info').get('user_name') if session.get('user_info') else None,
52-
request.remote_addr, method, url,
52+
remote_addr, method, url,
5353
','.join([str(x) for x in data_list if x]),
5454
response_message)
5555
else:
5656
logger.warning("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求参数:{}||请求结果:{}",
5757
session.get('user_info').get('user_name') if session.get('user_info') else None,
58-
request.remote_addr, method, url,
58+
remote_addr, method, url,
5959
','.join([str(x) for x in data_list if x]),
6060
response_message)
6161

6262
return response if stream else response.json()
6363
except Exception as e:
6464
logger.error("[api]请求人:{}||请求IP:{}||请求方法:{}||请求Api:{}||请求结果:{}",
6565
session.get('user_info').get('user_name') if session.get('user_info') else None,
66-
request.remote_addr, method, url, str(e))
66+
remote_addr, method, url, str(e))
6767
session['code'] = 500
6868
session['message'] = str(e)
6969

0 commit comments

Comments
 (0)