41 Commits

Author SHA1 Message Date
insistence
34f9e891b6 !9 RuoYi-Vue3-FastAPI v1.1.2
Merge pull request !9 from insistence/develop
2024-04-29 01:07:48 +00:00
insistence
fb9dfa4674 docs: 更新README文档 2024-04-29 08:52:12 +08:00
insistence
bbb7214cee chore: 升级版本至1.1.2 2024-04-29 08:43:57 +08:00
insistence
52e92d50d1 perf: 使用@lru_cache缓存ip归属区域查询结果,避免重复调用ip归属区域查询接口以优化性能 2024-04-24 10:03:52 +08:00
insistence
816793b888 feat: 配置文件新增数据库连接池相关配置 2024-04-23 09:04:49 +08:00
insistence
e774e1b26b fix: 修复个人中心修改密码后端异常的问题 2024-04-20 12:55:43 +08:00
insistence
42009cf3f4 !8 RuoYi-Vue3-FastAPI v1.1.1
Merge pull request !8 from insistence/develop
2024-04-19 03:40:20 +00:00
insistence
f4afa20ac2 docs: 更新README文档 2024-04-19 11:39:04 +08:00
insistence
7fd3109b52 chore: 升级版本至1.1.1 2024-04-19 11:38:12 +08:00
insistence
dfb8af23b3 fix: 修复添加菜单时是否外链和是否缓存回显异常的问题 2024-04-19 11:31:24 +08:00
insistence
b423647ad5 fix: 修复获取路由信息时菜单排序不生效的问题 2024-04-17 16:03:49 +08:00
insistence
423491302d fix: 修复菜单配置路由参数不生效的问题 2024-04-17 10:51:16 +08:00
insistence
fa27fd3b68 fix: 修复编辑角色数据权限时后端异常的问题 #I9ENQN 2024-04-08 11:04:32 +08:00
insistence
88b27685c1 fix: 修复编辑定时任务时更新的信息未同步至scheduler的问题 #I9EK56 2024-04-08 11:02:41 +08:00
insistence
2bade4d6c9 !7 RuoYi-Vue3-FastAPI v1.1.0
Merge pull request !7 from insistence/develop
2024-04-02 03:08:22 +00:00
insistence
a06c9f17d6 docs: 更新README文档 2024-04-02 10:47:48 +08:00
insistence
3654f4d88b chore: 升级版本至1.1.0 2024-04-02 10:45:44 +08:00
insistence
38aca38d4d feat: 后端配置文件新增账号同时登录开关配置 2024-04-02 10:42:07 +08:00
insistence
a57d737261 feat: 后端配置文件新增IP归属区域查询开关配置 2024-04-02 09:52:07 +08:00
insistence
84f56da523 feat: 后端配置文件新增sqlalchemy日志开关配置 2024-04-02 09:50:38 +08:00
insistence
f73a00e73c fix: 修复系统版本号或浏览器版本号无法获取时登录异常的问题 #I9CYNM 2024-04-01 09:56:22 +08:00
insistence
a84ad47de4 fix: 修复token本身过期时退出登录接口异常的问题 #I9CBWT 2024-03-29 11:08:00 +08:00
insistence
303612eed9 !6 RuoYi-Vue3-FastAPI v1.0.3
Merge pull request !6 from insistence/develop
2024-03-04 08:50:19 +00:00
insistence
dcb1f4d13c docs: 更新README文档 2024-03-04 15:50:48 +08:00
insistence
44ddc8c3a8 chore: 升级版本至1.0.3 2024-03-04 15:50:09 +08:00
insistence
70f6f8a471 fix: 修复添加和编辑菜单页面中是否缓存和是否外链字段回显异常的问题 #I95KBK 2024-03-04 15:49:45 +08:00
insistence
2a45df71cd fix: 修复外链菜单无法打开的问题 #I95KBK 2024-03-04 15:49:05 +08:00
insistence
eabeb705c4 feat: 账号密码登录新增IP黑名单校验 2024-03-04 15:47:13 +08:00
insistence
e9ad084dff !5 RuoYi-Vue3-FastAPI v1.0.2
Merge pull request !5 from insistence/develop
2024-02-18 07:12:52 +00:00
insistence
2e6c648126 docs: 更新README文档 2024-02-18 15:05:26 +08:00
insistence
153982436d chore: 升级版本号 2024-02-18 15:00:03 +08:00
insistence
45c3fa18e0 feat: 新增按角色校验接口权限依赖 2024-02-18 11:10:51 +08:00
insistence
3361fca5d2 feat: 用户接口权限校验增加列表接收参数,实现同一接口支持多个权限标识校验 2024-02-18 11:10:03 +08:00
insistence
b65aa4eea7 fix: 修复用户管理和部门管理模块数据权限异常的问题 2024-02-18 11:09:08 +08:00
insistence
7c4f0d1cb3 chore: 调整菜单管理模块部分接口权限标识 2024-02-18 11:08:53 +08:00
insistence
00520bc227 chore: 调整角色管理模块部分接口权限标识 2024-02-18 11:08:36 +08:00
insistence
bb94d38d53 chore: 调整日志管理模块部分接口权限标识 2024-02-18 11:08:21 +08:00
insistence
3ac12cab8c chore: 调整定时任务模块部分接口权限标识 2024-02-18 11:08:07 +08:00
insistence
4ea6fa7817 chore: 调整字典管理模块部分接口权限标识 2024-02-18 11:07:52 +08:00
insistence
fa065dfe45 chore: 调整部门管理模块部分接口权限标识 2024-02-18 11:07:36 +08:00
insistence
0a3102bdcf chore: 调整参数设置模块部分接口权限标识 2024-02-18 11:07:14 +08:00
27 changed files with 292 additions and 166 deletions

View File

@@ -1,21 +1,26 @@
<p align="center">
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
</p>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue3-FastAPI v1.0.1</h1>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue3-FastAPI v1.1.2</h1>
<h4 align="center">基于RuoYi-Vue3+FastAPI前后端分离的快速开发框架</h4>
<p align="center">
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/stargazers"><img src="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/badge/star.svg?theme=dark"></a>
<a href="https://github.com/insistence/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/github/stars/insistence/RuoYi-Vue3-FastAPI?style=social"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/badge/RuoYiVue3FastAPI-v1.0.1-brightgreen.svg"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/badge/RuoYiVue3FastAPI-v1.1.2-brightgreen.svg"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
<img src="https://img.shields.io/badge/python-≥3.8-blue">
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
</p>
## 平台简介
RuoYi-Vue-FastAPI是一套全部开源的快速开发平台毫无保留给个人及企业免费使用。
RuoYi-Vue3-FastAPI是一套全部开源的快速开发平台毫无保留给个人及企业免费使用。
* 前端采用Vue、Element Plus基于<u>[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3)</u>前端项目修改。
* 后端采用FastAPI、sqlalchemy、MySQL、Redis、OAuth2 & Jwt。

View File

@@ -2,7 +2,7 @@
# 应用运行环境
APP_ENV = 'dev'
# 应用名称
APP_NAME = 'RuoYi-FasAPI'
APP_NAME = 'RuoYi-FastAPI'
# 应用代理路径
APP_ROOT_PATH = '/dev-api'
# 应用主机
@@ -10,9 +10,13 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
APP_VERSION= '1.0.0'
APP_VERSION= '1.1.2'
# 应用是否开启热重载
APP_RELOAD = true
# 应用是否开启IP归属区域查询
APP_IP_LOCATION_QUERY = true
# 应用是否允许账号同时登录
APP_SAME_TIME_LOGIN = true
# -------- Jwt配置 --------
# Jwt秘钥
@@ -36,6 +40,16 @@ DB_USERNAME = 'root'
DB_PASSWORD = 'mysqlroot'
# 数据库名称
DB_DATABASE = 'ruoyi-fastapi'
# 是否开启sqlalchemy日志
DB_ECHO = true
# 允许溢出连接池大小的最大连接数
DB_MAX_OVERFLOW = 10
# 连接池大小0表示连接数无限制
DB_POOL_SIZE = 50
# 连接回收时间(单位:秒)
DB_POOL_RECYCLE = 3600
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
DB_POOL_TIMEOUT = 30
# -------- Redis配置 --------
# Redis主机

View File

@@ -2,7 +2,7 @@
# 应用运行环境
APP_ENV = 'prod'
# 应用名称
APP_NAME = 'RuoYi-FasAPI'
APP_NAME = 'RuoYi-FastAPI'
# 应用代理路径
APP_ROOT_PATH = '/prod-api'
# 应用主机
@@ -10,9 +10,13 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
APP_VERSION= '1.0.0'
APP_VERSION= '1.1.2'
# 应用是否开启热重载
APP_RELOAD = false
# 应用是否开启IP归属区域查询
APP_IP_LOCATION_QUERY = true
# 应用是否允许账号同时登录
APP_SAMETIME_LOGIN = true
# -------- Jwt配置 --------
# Jwt秘钥
@@ -36,6 +40,16 @@ DB_USERNAME = 'root'
DB_PASSWORD = 'root'
# 数据库名称
DB_DATABASE = 'ruoyi-fastapi'
# 是否开启sqlalchemy日志
DB_ECHO = true
# 允许溢出连接池大小的最大连接数
DB_MAX_OVERFLOW = 10
# 连接池大小0表示连接数无限制
DB_POOL_SIZE = 50
# 连接回收时间(单位:秒)
DB_POOL_RECYCLE = 3600
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
DB_POOL_TIMEOUT = 30
# -------- Redis配置 --------
# Redis主机

View File

@@ -8,7 +8,12 @@ SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.db_username}:{quote_
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, echo=True
SQLALCHEMY_DATABASE_URL,
echo=DataBaseConfig.db_echo,
max_overflow=DataBaseConfig.db_max_overflow,
pool_size=DataBaseConfig.db_pool_size,
pool_recycle=DataBaseConfig.db_pool_recycle,
pool_timeout=DataBaseConfig.db_pool_timeout
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()

View File

@@ -17,6 +17,8 @@ class AppSettings(BaseSettings):
app_port: int = 9099
app_version: str = '1.0.0'
app_reload: bool = True
app_ip_location_query: bool = True
app_same_time_login: bool = True
class JwtSettings(BaseSettings):
@@ -38,6 +40,11 @@ class DataBaseSettings(BaseSettings):
db_username: str = 'root'
db_password: str = 'mysqlroot'
db_database: str = 'ruoyi-fastapi'
db_echo: bool = True
db_max_overflow: int = 10
db_pool_size: int = 50
db_pool_recycle: int = 3600
db_pool_timeout: int = 30
class RedisSettings(BaseSettings):

View File

@@ -1,4 +1,4 @@
from functools import wraps
from functools import wraps, lru_cache
from fastapi import Request
from fastapi.responses import JSONResponse, ORJSONResponse, UJSONResponse
import inspect
@@ -12,6 +12,7 @@ from typing import Optional
from module_admin.service.login_service import LoginService
from module_admin.service.log_service import OperationLogService, LoginLogService
from module_admin.entity.vo.log_vo import OperLogModel, LogininforModel
from config.env import AppConfig
def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'operation'):
@@ -50,22 +51,8 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
# 获取请求的ip及ip归属区域
oper_ip = request.headers.get("X-Forwarded-For")
oper_location = '内网IP'
try:
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}')
if ip_result.status_code == 200:
prov = ip_result.json().get('data').get('prov')
city = ip_result.json().get('data').get('city')
if prov or city:
oper_location = f'{prov}-{city}'
else:
oper_location = '未知'
else:
oper_location = '未知'
except Exception as e:
oper_location = '未知'
print(e)
finally:
if AppConfig.app_ip_location_query:
oper_location = get_ip_location(oper_ip)
# 根据不同的请求类型使用不同的方法获取请求参数
content_type = request.headers.get("Content-Type")
if content_type and ("multipart/form-data" in content_type or 'application/x-www-form-urlencoded' in content_type):
@@ -91,8 +78,12 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
login_log = {}
if log_type == 'login':
user_agent_info = parse(user_agent)
browser = f'{user_agent_info.browser.family} {user_agent_info.browser.version[0]}'
system_os = f'{user_agent_info.os.family} {user_agent_info.os.version[0]}'
browser = f'{user_agent_info.browser.family}'
system_os = f'{user_agent_info.os.family}'
if user_agent_info.browser.version != ():
browser += f' {user_agent_info.browser.version[0]}'
if user_agent_info.os.version != ():
system_os += f' {user_agent_info.os.version[0]}'
login_log = dict(
ipaddr=oper_ip,
loginLocation=oper_location,
@@ -170,3 +161,26 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope
return wrapper
return decorator
@lru_cache()
def get_ip_location(oper_ip: str):
"""
查询ip归属区域
:param oper_ip: 需要查询的ip
:return: ip归属区域
"""
oper_location = '内网IP'
try:
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
oper_location = '未知'
ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}')
if ip_result.status_code == 200:
prov = ip_result.json().get('data').get('prov')
city = ip_result.json().get('data').get('city')
if prov or city:
oper_location = f'{prov}-{city}'
except Exception as e:
oper_location = '未知'
print(e)
return oper_location

View File

@@ -1,4 +1,5 @@
from fastapi import Depends
from typing import Union, List
from module_admin.entity.vo.user_vo import CurrentUserModel
from module_admin.service.login_service import LoginService
from exceptions.exception import PermissionException
@@ -7,13 +8,52 @@ from exceptions.exception 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: CurrentUserModel = Depends(LoginService.get_current_user)):
user_auth_list = current_user.permissions
user_auth_list.append('common')
if '*:*:*' in user_auth_list or self.perm_str in user_auth_list:
if '*:*:*' 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: CurrentUserModel = Depends(LoginService.get_current_user)):
user_role_list = current_user.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="该用户无此接口权限")

View File

@@ -62,7 +62,7 @@ async def edit_system_config(request: Request, edit_config: ConfigModel, query_d
return ResponseUtil.error(msg=str(e))
@configController.delete("/refreshCache", dependencies=[Depends(CheckUserInterfaceAuth('system:config:edit'))])
@configController.delete("/refreshCache", dependencies=[Depends(CheckUserInterfaceAuth('system:config:remove'))])
@log_decorator(title='参数管理', business_type=2)
async def refresh_system_config(request: Request, query_db: Session = Depends(get_db)):
try:

View File

@@ -13,7 +13,7 @@ from module_admin.annotation.log_annotation import log_decorator
deptController = APIRouter(prefix='/system/dept', dependencies=[Depends(LoginService.get_current_user)])
@deptController.get("/list/exclude/{dept_id}", response_model=List[DeptModel], dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@deptController.get("/list/exclude/{dept_id}", response_model=List[DeptModel], dependencies=[Depends(CheckUserInterfaceAuth('system:dept:list'))])
async def get_system_dept_tree_for_edit_option(request: Request, dept_id: int, query_db: Session = Depends(get_db), data_scope_sql: str = Depends(GetDataScope('SysDept'))):
try:
dept_query = DeptModel(deptId=dept_id)

View File

@@ -62,7 +62,7 @@ async def edit_system_dict_type(request: Request, edit_dict_type: DictTypeModel,
return ResponseUtil.error(msg=str(e))
@dictController.delete("/type/refreshCache", dependencies=[Depends(CheckUserInterfaceAuth('system:dict:edit'))])
@dictController.delete("/type/refreshCache", dependencies=[Depends(CheckUserInterfaceAuth('system:dict:remove'))])
@log_decorator(title='字典管理', business_type=2)
async def refresh_system_dict(request: Request, query_db: Session = Depends(get_db)):
try:
@@ -95,7 +95,7 @@ async def delete_system_dict_type(request: Request, dict_ids: str, query_db: Ses
return ResponseUtil.error(msg=str(e))
@dictController.get("/type/optionselect", response_model=List[DictTypeModel], dependencies=[Depends(CheckUserInterfaceAuth('system:dict:query'))])
@dictController.get("/type/optionselect", response_model=List[DictTypeModel])
async def query_system_dict_type_options(request: Request, query_db: Session = Depends(get_db)):
try:
dict_type_query_result = DictTypeService.get_dict_type_list_services(query_db, DictTypePageQueryModel(**dict()), is_page=False)
@@ -131,7 +131,7 @@ async def export_system_dict_type_list(request: Request, dict_type_page_query: D
return ResponseUtil.error(msg=str(e))
@dictController.get("/data/type/{dict_type}", dependencies=[Depends(CheckUserInterfaceAuth('system:dict:list'))])
@dictController.get("/data/type/{dict_type}")
async def query_system_dict_type_data(request: Request, dict_type: str, query_db: Session = Depends(get_db)):
try:
# 获取全量数据

View File

@@ -63,7 +63,7 @@ async def edit_system_job(request: Request, edit_job: EditJobModel, query_db: Se
return ResponseUtil.error(msg=str(e))
@jobController.put("/job/changeStatus", dependencies=[Depends(CheckUserInterfaceAuth('monitor:job:edit'))])
@jobController.put("/job/changeStatus", dependencies=[Depends(CheckUserInterfaceAuth('monitor:job:changeStatus'))])
@log_decorator(title='定时任务管理', business_type=2)
async def edit_system_job(request: Request, edit_job: EditJobModel, query_db: Session = Depends(get_db), current_user: CurrentUserModel = Depends(LoginService.get_current_user)):
try:

View File

@@ -70,7 +70,7 @@ async def export_system_operation_log_list(request: Request, operation_log_page_
return ResponseUtil.streaming(data=bytes2file_response(operation_log_export_result))
except Exception as e:
logger.exception(e)
return response_500(data="", message=str(e))
return ResponseUtil.error(msg=str(e))
@logController.get("/logininfor/list", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('monitor:logininfor:list'))])

View File

@@ -41,11 +41,13 @@ async def login(request: Request, form_data: CustomOAuth2PasswordRequestForm = D
},
expires_delta=access_token_expires
)
if AppConfig.app_same_time_login:
await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{session_id}", access_token,
ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
else:
# 此方法可实现同一账号同一时间只能登录一次
# await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{result[0].user_id}", access_token,
# ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{result[0].user_id}", access_token,
ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
UserService.edit_user_services(query_db, EditUserModel(userId=result[0].user_id, loginDate=datetime.now(), type='status'))
logger.info('登录成功')
# 判断请求是否来自于api文档如果是返回指定格式的结果用于修复api文档认证成功后token显示undefined的bug
@@ -131,7 +133,7 @@ async def register_user(request: Request, user_register: UserRegister, query_db:
@loginController.post("/logout")
async def logout(request: Request, token: Optional[str] = Depends(oauth2_scheme)):
try:
payload = jwt.decode(token, JwtConfig.jwt_secret_key, algorithms=[JwtConfig.jwt_algorithm])
payload = jwt.decode(token, JwtConfig.jwt_secret_key, algorithms=[JwtConfig.jwt_algorithm], options={'verify_exp': False})
session_id: str = payload.get("session_id")
await LoginService.logout_services(request, session_id)
logger.info('退出成功')

View File

@@ -12,7 +12,7 @@ from module_admin.annotation.log_annotation import log_decorator
menuController = APIRouter(prefix='/system/menu', dependencies=[Depends(LoginService.get_current_user)])
@menuController.get("/treeselect", dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@menuController.get("/treeselect")
async def get_system_menu_tree(request: Request, query_db: Session = Depends(get_db), current_user: CurrentUserModel = Depends(LoginService.get_current_user)):
try:
menu_query_result = MenuService.get_menu_tree_services(query_db, current_user)
@@ -23,7 +23,7 @@ async def get_system_menu_tree(request: Request, query_db: Session = Depends(get
return ResponseUtil.error(msg=str(e))
@menuController.get("/roleMenuTreeselect/{role_id}", dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@menuController.get("/roleMenuTreeselect/{role_id}")
async def get_system_role_menu_tree(request: Request, role_id: int, query_db: Session = Depends(get_db), current_user: CurrentUserModel = Depends(LoginService.get_current_user)):
try:
role_menu_query_result = MenuService.get_role_menu_tree_services(query_db, role_id, current_user)

View File

@@ -17,7 +17,7 @@ from module_admin.annotation.log_annotation import log_decorator
roleController = APIRouter(prefix='/system/role', dependencies=[Depends(LoginService.get_current_user)])
@roleController.get("/deptTree/{role_id}", dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@roleController.get("/deptTree/{role_id}", dependencies=[Depends(CheckUserInterfaceAuth('system:role:query'))])
async def get_system_role_dept_tree(request: Request, role_id: int, query_db: Session = Depends(get_db), data_scope_sql: str = Depends(GetDataScope('SysDept'))):
try:
dept_query_result = DeptService.get_dept_tree_services(query_db, DeptModel(**{}), data_scope_sql)
@@ -160,7 +160,7 @@ async def reset_system_role_status(request: Request, edit_role: AddRoleModel, qu
return ResponseUtil.error(msg=str(e))
@roleController.get("/authUser/allocatedList", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@roleController.get("/authUser/allocatedList", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('system:role:list'))])
async def get_system_allocated_user_list(request: Request, user_role: UserRolePageQueryModel = Depends(UserRolePageQueryModel.as_query), query_db: Session = Depends(get_db)):
try:
role_user_allocated_page_query_result = RoleService.get_role_user_allocated_list_services(query_db, user_role, is_page=True)
@@ -171,7 +171,7 @@ async def get_system_allocated_user_list(request: Request, user_role: UserRolePa
return ResponseUtil.error(msg=str(e))
@roleController.get("/authUser/unallocatedList", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('common'))])
@roleController.get("/authUser/unallocatedList", response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('system:role:list'))])
async def get_system_unallocated_user_list(request: Request, user_role: UserRolePageQueryModel = Depends(UserRolePageQueryModel.as_query), query_db: Session = Depends(get_db)):
try:
role_user_unallocated_page_query_result = RoleService.get_role_user_unallocated_list_services(query_db, user_role, is_page=True)

View File

@@ -1,5 +1,6 @@
from sqlalchemy.orm import Session
from module_admin.entity.do.dept_do import SysDept
from module_admin.entity.do.role_do import SysRoleDept
from module_admin.entity.vo.dept_vo import *
from utils.time_format_util import list_format_datetime

View File

@@ -1,7 +1,7 @@
from sqlalchemy import and_, or_, desc, func
from sqlalchemy.orm import Session
from module_admin.entity.do.user_do import SysUser, SysUserRole, SysUserPost
from module_admin.entity.do.role_do import SysRole, SysRoleMenu
from module_admin.entity.do.role_do import SysRole, SysRoleDept, SysRoleMenu
from module_admin.entity.do.dept_do import SysDept
from module_admin.entity.do.post_do import SysPost
from module_admin.entity.do.menu_do import SysMenu

View File

@@ -72,6 +72,7 @@ class JobService:
if query_job:
SchedulerUtil.remove_scheduler_job(job_id=edit_job.get('job_id'))
if edit_job.get('status') == '0':
job_info = cls.job_detail_services(query_db, edit_job.get('job_id'))
SchedulerUtil.add_scheduler_job(job_info=job_info)
query_db.commit()
result = dict(is_success=True, message='更新成功')

View File

@@ -56,6 +56,7 @@ class LoginService:
:param login_user: 登录用户对象
:return: 校验结果
"""
await cls.__check_login_ip(request)
account_lock = await request.app.state.redis.get(
f"{RedisInitKeyConfig.ACCOUNT_LOCK.get('key')}:{login_user.user_name}")
if login_user.user_name == account_lock:
@@ -100,6 +101,21 @@ class LoginService:
f"{RedisInitKeyConfig.PASSWORD_ERROR_COUNT.get('key')}:{login_user.user_name}")
return user
@classmethod
async def __check_login_ip(cls, request: Request):
"""
校验用户登录ip是否在黑名单内
:param request: Request对象
:return: 校验结果
"""
black_ip_value = await request.app.state.redis.get(
f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.login.blackIPList")
black_ip_list = black_ip_value.split(',') if black_ip_value else []
if request.headers.get('X-Forwarded-For') in black_ip_list:
logger.warning("当前IP禁止登录")
raise LoginException(data="", message="当前IP禁止登录")
return True
@classmethod
async def __check_login_captcha(cls, request: Request, login_user: UserLogin):
"""
@@ -166,14 +182,18 @@ class LoginService:
if query_user.get('user_basic_info') is None:
logger.warning("用户token不合法")
raise AuthException(data="", message="用户token不合法")
if AppConfig.app_same_time_login:
redis_token = await request.app.state.redis.get(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{session_id}")
else:
# 此方法可实现同一账号同一时间只能登录一次
# redis_token = await request.app.state.redis.get(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{user.user_basic_info.user_id}")
redis_token = await request.app.state.redis.get(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{query_user.get('user_basic_info').user_id}")
if token == redis_token:
if AppConfig.app_same_time_login:
await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{session_id}", redis_token,
ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
# await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{user.user_basic_info.user_id}", redis_token,
# ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
else:
await request.app.state.redis.set(f"{RedisInitKeyConfig.ACCESS_TOKEN.get('key')}:{query_user.get('user_basic_info').user_id}", redis_token,
ex=timedelta(minutes=JwtConfig.jwt_redis_expire_minutes))
role_id_list = [item.role_id for item in query_user.get('user_role_info')]
if 1 in role_id_list:
@@ -209,7 +229,7 @@ class LoginService:
:return: 当前用户路由信息对象
"""
query_user = UserDao.get_user_by_id(query_db, user_id=user_id)
user_router_menu = [row for row in query_user.get('user_menu_info') if row.menu_type in ['M', 'C']]
user_router_menu = sorted([row for row in query_user.get('user_menu_info') if row.menu_type in ['M', 'C']], key=lambda x: x.order_num)
user_router = cls.__generate_user_router_menu(0, user_router_menu)
return user_router
@@ -229,14 +249,16 @@ class LoginService:
if permission.menu_type == 'M':
router_list_data['name'] = permission.path.capitalize()
router_list_data['hidden'] = False if permission.visible == '0' else True
if permission.is_frame == 1:
router_list_data['redirect'] = 'noRedirect'
if permission.parent_id == 0:
router_list_data['component'] = 'Layout'
router_list_data['path'] = f'/{permission.path}'
else:
router_list_data['component'] = 'ParentView'
router_list_data['path'] = permission.path
if permission.is_frame == 1:
router_list_data['redirect'] = 'noRedirect'
else:
router_list_data['path'] = permission.path
if children:
router_list_data['alwaysShow'] = True
router_list_data['children'] = children
@@ -249,6 +271,7 @@ class LoginService:
elif permission.menu_type == 'C':
router_list_data['name'] = permission.path.capitalize()
router_list_data['path'] = permission.path
router_list_data['query'] = permission.query
router_list_data['hidden'] = False if permission.visible == '0' else True
router_list_data['component'] = permission.component
router_list_data['meta'] = {

View File

@@ -131,7 +131,7 @@ class RoleService:
:param page_object: 角色数据权限对象
:return: 分配角色数据权限结果
"""
edit_role = page_object.model_dump(exclude_unset=True)
edit_role = page_object.model_dump(exclude_unset=True, exclude={'admin'})
del edit_role['dept_ids']
role_info = cls.role_detail_services(query_db, edit_role.get('role_id'))
if role_info:

View File

@@ -206,7 +206,7 @@ class UserService:
:param page_object: 重置用户对象
:return: 重置用户校验结果
"""
reset_user = page_object.model_dump(exclude_unset=True)
reset_user = page_object.model_dump(exclude_unset=True, exclude={'admin'})
if page_object.old_password:
user = UserDao.get_user_detail_by_id(query_db, user_id=page_object.user_id).get('user_basic_info')
if not PwdUtil.verify_password(page_object.old_password, user.password):

View File

@@ -4,5 +4,5 @@ VITE_APP_TITLE = vfadmin管理系统
# 开发环境配置
VITE_APP_ENV = 'development'
# 若依管理系统/开发环境
# vfadmin管理系统/开发环境
VITE_APP_BASE_API = '/dev-api'

View File

@@ -4,7 +4,7 @@ VITE_APP_TITLE = vfadmin管理系统
# 生产环境配置
VITE_APP_ENV = 'production'
# 若依管理系统/生产环境
# vfadmin管理系统/生产环境
VITE_APP_BASE_API = '/prod-api'
# 是否在打包时开启压缩,支持 gzip 和 brotli

View File

@@ -1,10 +1,10 @@
# 页面标题
VITE_APP_TITLE = 若依管理系统
VITE_APP_TITLE = vfadmin管理系统
# 生产环境配置
VITE_APP_ENV = 'staging'
# 若依管理系统/生产环境
# vfadmin管理系统/生产环境
VITE_APP_BASE_API = '/stage-api'
# 是否在打包时开启压缩,支持 gzip 和 brotli

View File

@@ -7,7 +7,7 @@
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="icon" href="/favicon.ico">
<title>若依管理系统</title>
<title>vfadmin管理系统</title>
<!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
<style>
html,

View File

@@ -1,6 +1,6 @@
{
"name": "vfadmin",
"version": "1.0.0",
"version": "1.1.2",
"description": "vfadmin管理系统",
"author": "insistence",
"license": "MIT",

View File

@@ -152,8 +152,8 @@
</span>
</template>
<el-radio-group v-model="form.isFrame">
<el-radio label="0"></el-radio>
<el-radio label="1"></el-radio>
<el-radio :label="0"></el-radio>
<el-radio :label="1"></el-radio>
</el-radio-group>
</el-form-item>
</el-col>
@@ -220,8 +220,8 @@
</span>
</template>
<el-radio-group v-model="form.isCache">
<el-radio label="0">缓存</el-radio>
<el-radio label="1">不缓存</el-radio>
<el-radio :label="0">缓存</el-radio>
<el-radio :label="1">不缓存</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
@@ -339,8 +339,8 @@ function reset() {
icon: undefined,
menuType: "M",
orderNum: undefined,
isFrame: "1",
isCache: "0",
isFrame: 1,
isCache: 0,
visible: "0",
status: "0"
};